我正在尝试获取确认消息,同时在GridView中单击上的删除按钮。如果我符合,则只删除GridView中的行。
*.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 !";
}发布于 2013-10-28 13:11:22
我有回答的朋友
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="deletebtn" runat="server" CommandName="Delete"
Text="Delete" OnClientClick="return confirm('Are you sure?');" />
</ItemTemplate>
</asp:TemplateField>我把CommandField改为TemplateField
谢谢!
发布于 2013-10-28 12:36:11
如下所示更改行数据库事件。
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Button)e.Row.Cells[0].Controls[0]).OnClientClick = "return confirm('Are you sure you want to delete?');";
}
}发布于 2014-02-13 05:04:31
只需在onclientclick事件上调用javascript函数并请求确认。如果它返回true,则可以调用服务器端代码来删除。
下面是解释的代码
<asp:LinkButton ID="lbDelete" runat="server" OnClick="lbDelete_Click" OnClientClick="return fnConfirm();"> Delete</asp:LinkButton>下面是javascript函数:
<script type="text/javascript">
function fnConfirm() {
if (confirm("The item will be deleted. Are you sure want to continue?") == true)
return true;
else
return false;
}
</script>您可以在下面的链接中使用源代码查看详细文章。
http://www.dotnetpickles.com/2013/03/how-to-show-confirm-message-while.html
谢谢
https://stackoverflow.com/questions/19634454
复制相似问题