在后台中添加GridView的 RowCreated事件,如下代码:
e.Row.Cells[index])表示按钮在行中的第几个单元格,填对应的索引号,
protected void GVInfo_RowCreated(object sender, GridViewRowEventArgs e)
{
(e.Row.Cells[2]).Attributes.Add("onclick", "javascript:return confirm('确定要删除吗?')");
}
个人觉得ButtonField有很多问题,不推荐使用,还是用模板列比较方便-------
<span id="message" onclick="JavaScript:return confirm('確定要刪除嗎?')">
模板列前台示例(vs2010):
<asp:TemplateField HeaderText="刪除">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<span id="message" onclick="JavaScript:return confirm('確定要刪除嗎?')">
<asp:LinkButton ID="lnkDel" runat="server" onclick="lnkDel_Click">刪除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
以下为来源网络:
实现对gridview删除行时弹出确认对话框的一种简单方法
相关资料链接:http://blog.csdn.net/waterxcfg304/article/details/23512211

本文介绍如何在ASP.NET GridView中实现删除操作前的确认提示,通过RowCreated事件或模板列设置JavaScript确认对话框。

7113

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



