简体   繁体   中英

RowEditing is fired when update button is clicked in GridView

I have created a GridView as below:

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 also written the following methods:-

RowUpdating :

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;
}

RowEditing :

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 ran the codes in debugging mode, clicking on the update button invokes gv_RowEditing method instead of gv_RowUpdating . What is the problem?

The Sequence of firing the events of gridview when you click on edit button to update any record it calls rowediting event and after that when you click on update button it calls rowupdating event. rowediting event always invokes first then rowupdating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM