如果你想在删除GridView中一行记录的时候让系统给出一个提示信息,使得用户能在确认删除前能选择放弃此操作,我认为最简单的方法是给GridView增加一个模板字段,类型可以为LinkButton或者Button,注意其CommandName要设置为"Delete",其OnClientClick属性要设置成如下的形式:'return confirm("Are you sure???");' 详细的例子如下:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
...
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("Are you sure you want to delete this entry?");'
Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
上述功能我已经测试过,希望对大家有帮助
原文地址: http://pluralsight.com/blogs/fritz/archive/2006/03/22/20514.aspx(2006/7/27查询有效)
<asp:GridView ID="GridView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
...
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("Are you sure you want to delete this entry?");'
Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
上述功能我已经测试过,希望对大家有帮助
原文地址: http://pluralsight.com/blogs/fritz/archive/2006/03/22/20514.aspx(2006/7/27查询有效)