本文介绍了row_editing在网格视图中单击更新按钮时触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我出了什么问题?我已经以编程方式创建了gridview,如下所示。

I don't know whats going wrong with me? I have created gridview programmatically 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 written following methods.

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



}

但是当我在调试模式下运行它时...点击更新按钮调用gv_RowEditing方法而不是gv_RowUpdating ....



请帮助。


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

Please Help.

推荐答案

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 :)


这篇关于row_editing在网格视图中单击更新按钮时触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 01:13