From dePoPo.net

Adding a delete confirmation to a gridview

Posted in: ASP.NET
By
Oct 7, 2009 - 8:49:47 PM

credit: http://www.pluralsight.com/community/blogs/fritz/archive/2006/03/22/20514.aspx

* A DELETE command needs to be bound to your datasource for this to work
* If you need to delete refrenced tables, you are out of luck with this approach and will need to write the code to handle the removal of data from the linked tables first.


<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>


© Copyright 2010 by dePoPo.net