方法一(已测试):
首先将按钮那一列转化为模版,然后在其属性里加入下面的js语句,就能弹出一个确认窗口。
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
Text="选择" >
</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="删除"
OnClientClick="return confirm( Are you sure you want to delete this record? )" >
</asp:LinkButton>
</ItemTemplate>
方法二(已测试):
按钮类型选择:linkbutton
((LinkButton)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", " return confirm('你确定要删除吗');")
方法三(未测试):在Page_Load里面先注册一段服务器端脚本:
if (!Page.ClientScript.IsClientScriptBlockRegistered("deleteConfirmBlock"))
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "deleteConfirmBlock", "function deleteConfirm(){confirm( 确认要删除? );}", true);
}
然后在“删除”按钮的响应函数里面调用这段脚本:
if(Page.ClientScript.IsStartupScriptRegistered("deleteConfirmBlock")){
Page.ClientScript.RegisterStartupScript(typeof(string), "deleteConfirmBlock","confirmDelete()");
}
//后面的就是删除动作