This question seems to come up quite a bit, so I thought I'd post the solution I prefer for everyone's reference. If you want to add a client-side prompt to a GridView's delete function, so that the user has a chance to say 'no, I didn't mean that!', the simplest way I have found is to add a template field to the GridView with a LinkButton (or plain Button if you prefer) whose CommandName is set to "Delete" and whose OnClientClick property is set to something like 'return confirm("Are you sure???");' - for example:
<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>
Hope this helps!
 |
Limited training time? Need to learn ASP.NET 2.0 and SQL Server 2005?
|
Posted
Mar 22 2006, 01:08 PM
by
fritz-onion