Asp.net 以编程方式将OnRowDelete添加到GridView
我正在通过编程生成Asp.net 以编程方式将OnRowDelete添加到GridView,asp.net,gridview,commandfield,Asp.net,Gridview,Commandfield,我正在通过编程生成GridViews,每个GridView都有一个带有删除按钮的CommandField。如何通过编程方式添加OnDeletingRow,以便在单击带有GridView的删除按钮时调用函数 GridView gv = new GridView(); gv.AutoGenerateColumns = false; gv.ID = "GridView_" + sel
GridView
s,每个GridView
都有一个带有删除按钮的CommandField
。如何通过编程方式添加OnDeletingRow
,以便在单击带有GridView
的删除按钮时调用函数
GridView gv = new GridView();
gv.AutoGenerateColumns = false;
gv.ID = "GridView_" + selectedId;
gv.DataKeyNames = new string[] {"id"};
gv.AllowPaging = false;
gv.CellPadding = 3;
gv.RowDeleting += new GridViewDeleteEventHandler(gv_RowDeleting);
CommandField commandfieldDeallocate = new CommandField();
commandfieldDeallocate.HeaderText = "DELETE NUMBER";
commandfieldDeallocate.ShowDeleteButton = true;
commandfieldDeallocate.DeleteText = "DELETE";
gv.Columns.Add(commandfieldDeallocate);
在C#中,您可以这样做:
gv.RowDeleting += new GridViewDeleteEventHandler(gv_RowDeleting);
void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
// Perform deletion
}
ConnorsFan,谢谢你的解决方案,但由于某种原因,我没有调用该函数,有什么想法吗?我已将我的代码添加到原始问题中。解决方案可能在本文中(幸运的是,答案比问题短得多):