Alan Moseley IT Consultancy

Blog Entry

6/13/2008 - Confirm delete within an asp GridView control

The standard delete commandfield within a gridview control does not give the user any warning that the record is about to be deleted. The best way that I have found (so far) to display a warning is to run a little client-side script. Within the CommandField of your gridview, set ShowDelete to False, and replace it with a TemplateField as shown below:-

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick='return confirm("Are you sure you want to delete this entry?");' Text="Delete" />