Click here to Skip to main content
15,891,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I don't know whats going wrong with me? I have created gridview programmatically as below.
C#
 protected void Page_Load(object sender, EventArgs e)
        {
     GridView gv = new GridView();
            gv.ID = pId.ToString();
            gv.AutoGenerateEditButton = true;
            gv.DataKeyNames = ids;
            gv.RowEditing += gv_RowEditing;
            gv.RowUpdating += gv_RowUpdating;
            bindGv(pId, gv);
}

I have written following methods.
C#
void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
         GridView gv = sender as GridView;
        GridViewRow row = (GridViewRow)gv.Rows[e.RowIndex];
        ProductCategory pc = context.ProductCategories.First(s => s.Name ==gv.ID );
         TextBox txtName = row.FindControl("txtName") as TextBox;
         pc.Name = txtName.Text;
    }

    void gv_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView gv = sender as GridView;
        gv.EditIndex = e.NewEditIndex;
        bindGv(Convert.ToInt32(gv.ID), gv);

}
But when I run it in debugging mode...clicking on update button invokes gv_RowEditing method instead of gv_RowUpdating....

Please Help.
Posted
Updated 22-Jul-15 22:14pm
v3

1 solution

Place the logic to bind the gridview inside IsPostback check in page_load like
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostback)
            {
               GridView gv = new GridView();
               gv.ID = pId.ToString();
               gv.AutoGenerateEditButton = true;
               gv.DataKeyNames = ids;
               gv.RowEditing += gv_RowEditing;
               gv.RowUpdating += gv_RowUpdating;
               bindGv(pId, gv);
            }
        }


Hope, it helps :)
 
Share this answer
 
Comments
Merajuddin Ansari 23-Jul-15 4:49am    
Had to change CausesValidation property of my commandButton to false.
and it's working fine.
thank you for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900