ASp.NET 2.0中的GridView,添加GridView的RowDataBound事件并添加以下类似代码
<asp:CommandField ShowDeleteButton="True" />
protected void GVColors_RowDataBound(object sender, GridViewRowEventArgs e)

{
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Cells[10].Attributes.Add("onclick", "javascript:return confirm('你确认要删除/"" + e.Row.Cells[1].Text + "/"吗?')");

}
注意:Cells[10]为删除按钮所在的列,删除按钮要在一个单独的列中,可以转化为模板列。
<asp:CommandField ShowDeleteButton="True" />
protected void GVColors_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Cells[10].Attributes.Add("onclick", "javascript:return confirm('你确认要删除/"" + e.Row.Cells[1].Text + "/"吗?')");
}注意:Cells[10]为删除按钮所在的列,删除按钮要在一个单独的列中,可以转化为模板列。
本文介绍如何在ASP.NET2.0的GridView控件中实现删除功能,通过添加RowDataBound事件及JavaScript确认对话框来确保用户在删除记录前进行确认。
836

被折叠的 条评论
为什么被折叠?



