我需要在gridview中单击自动生成删除按钮时显示确认消息。
我的代码在这里
AllowPaging="true" PageSize="10" OnClientClick="return confirm('Are you sure you want to delete this event?');"></asp:GridView>
protected void grdFraction_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int catid = int.Parse(grdFraction.DataKeys[e.RowIndex].Value.ToString());
var delQuery = "delete from nano_WasteFraction where FID='" + catid + "'";
SqlHelper.ExecuteNonQuery(GlobalSettings.DbDSN, CommandType.Text, delQuery);
GridBind();
}
我只是在gridviw中添加OnClientClick。但是它没有工作。任何一个帮助吗?
答案 0 :(得分:2)
您是否尝试在删除按钮标记上使用以下代码?
OnClientClick="return confirm('Are you sure you want to delete this?');"
它对我很有用。
答案 1 :(得分:1)
<script language="javascript" type="text/javascript">
function DisplayCancelMessage() {
var value = confirm("Are You Sure, You Want to delete this event?");
if (value) {
return true;
}
else {
return false;
}
}
</script>
And Add OnClientClick Property in to the delete button
OnClientClick="return DisplayCancelMessage();"
答案 2 :(得分:1)
尝试这样,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')");
}
}