NET web如何调出GridView中的删除按钮
要在.NET web中调出GridView中的删除按钮,可以按照以下步骤进行操作:
- 在GridView中添加一个CommandField列,设置其Button类型为Button,并设置其CommandName为"Delete",如下所示:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
<Columns>
<!-- 其他列 -->
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" CommandName="Delete" />
</Columns>
</asp:GridView>
- 在GridView的RowCommand事件中编写相应的处理代码,根据CommandName判断是否是删除操作,如下所示:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
// 根据行索引删除对应的数据
// 重新绑定GridView
}
}
在处理代码中,可以通过e.CommandArgument获取触发删除操作的行索引,然后根据该索引删除对应的数据,最后重新绑定GridView以显示更新后的数据。
原文地址: https://www.cveoy.top/t/topic/iQcm 著作权归作者所有。请勿转载和采集!