我正在尝试在 GridView 中单击 删除 按钮时获得 确认 消息。如果我 确认,则只有该行将从 GridView 中删除。
*.ASPX
*.ASPX
<Columns>
<asp:CommandField ButtonType="Button" ShowDeleteButton="true" />
</Columns>
*.ASPX.CS
protected void grdPersTable_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button buttonCommandField = e.Row.Cells[0].Controls[0] as Button;
buttonCommandField.Attributes["onClick"] =
string.Format("return confirm('Are you want delete ')");
}
}
protected void grdPersTable_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lbl0 = (Label)grdPersTable.Rows[e.RowIndex].FindControl("lblId");
txtId.Text = lbl0.Text;
obj.DeleteV(Convert.ToInt32(txtId.Text));
grdPersTable.DataSource = obj.GetTableValues();
grdPersTable.DataBind();
lblMessage.Text = "Deleted successfully !";
}