第一种解决方案:
先把你的删除按钮的那一列转化为模板列,然后再模板编辑里找到删除按钮,在你的删除按钮的OnclientClick属性中添加:
return confirm("确定删除?")
第二种解决方案:
点击GridView控件左上角的智能标记,选择编辑列,在出现的对话框中点击CommandField,选择删除按钮,点击添加,然后回到GridView控件,添加以下事件代码
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
foreach (TableCell tc in e.Row.Cells)
{
if (tc.Controls.Count > 0)
{
foreach (Control con in tc.Controls)
{
if (con.GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
LinkButton lb = (LinkButton)con;
if (lb.CommandName == "Delete")
{
lb.Attributes.Add("onclick", "return confirm('您真的要删除这条记录吗?')");
}
}
}
}
}
}