我的代码如下。我没有将我的数据存储在数据库中。我只是从 TextBox 中提取数据,并将其显示在 GridView 中。如何使用复选框和按钮从 GridView 中删除多行? //删除行的代码
ASPX 代码:
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkdelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
C#代码:
protected void btnDelete_Click(object sender, EventArgs e)
{
//Loop through all the rows in gridview
foreach(GridViewRow gvrow in gvUserDetails.Rows)
{
//Finiding checkbox control in gridview for particular row
CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete");
//Condition to check checkbox selected or not
if(chkdelete.Checked)
{
//code for deleting the row (What code do I write here?)
}
}
}