locked
Updating a GridView from a updated table RRS feed

  • Question

  • User841449844 posted

    Hi,

    Hopefully someone can point me in the right direction with this.

    I have a table that is updated with status information and I would like to display this in a gridview, using Ajax to update

    the control when a new table insert has been completed.

    As far as i can tell I should have my aspx GridView control configured and nested inside an ajax updatePanel, then databound to a datatable/dataset pertaining to

    to the database table in question, and possibly then using the trigger tags?

    Looking for some clarification on how i should be going about this, and if the above is on the right lines?

    Thanks,

    Jay

    Monday, March 3, 2014 11:10 PM

Answers

  • User-1131976214 posted

    Hi JRhys,

     here is my suggestion for your problems,mainly about the direction

    1 Create an asp.net web application, Add  an default.aspx page

    2  Add scriptmanage in your page  in the form tag like this:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    
    </asp:ScriptManager>

    3 Add updatepanel in your page:

     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    
     </asp:UpdatePanel>

    4 Add the datagrid inside the update panel :

    asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div>
                <asp:GridView id="GridView1" runat="server" CellPadding="4" AutoGenerateColumns="false" AutoGenerateColumns="false" onrowcancelingedit="RowCancelingEdit" onrowediting="RowEditing" onrowupdating="RowUpdating">
    <Columns>
    //column you want to show and display
    <Columns>

                </asp:GridView>
            </div>
        </ContentTemplate>
    < /asp:UpdatePanel>

    5  On page load bind the gridview ,like this:

    protected void Page_Load(object sender, EventArgs e)
    
            {
                 if (!IsPostBack)
    
                {
                    GridView1.DataSource =GetDataFromDataBase();
                    GridView1.DataBind();
    
                }
    
            }

    6 Handle the event about the gridview ,Like this:

    protected void RowEditing(object sender, GridViewEditEventArgs e)
    
            {
    
                GridView1.EditIndex = e.NewEditIndex;
    
                GridView1.DataSource = GetDataFromDataBase();
    
                GridView1.DataBind();
    
            }
    
            protected void RowUpdating(object sender, GridViewUpdateEventArgs e)
    
            {
    
    
            }
            protected void RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    
            {
    
                GridView1.EditIndex = -1;
    
                GridView1.DataSource = GetDataFromDataBase();
    
                GridView1.DataBind();
    
            }

    7 Run the applicatin,edit the gridview ,you will see the result.

     Hope my answer will be helpful for you ,

     if you still dont know how to use ajax updatepanel ,please refer to

    http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel(v=vs.100).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 4, 2014 1:53 AM