Wednesday, December 26, 2012

ASP.NET String Format Grid Link Button

Today I wanted create a link button to allow a user to delete an item with a confirmation message. However, I did not want to just say 'Are you sure you want to delete?'. I wanted it to be more customized like 'Are you sure you want to delete 'XYZ'? I was working in a GridView using a templated LinkButton. Eval statements are not my thing but I did find a post out there that suggested I do the following and it worked great.
 <asp:LinkButton ID="LinkButton1" 
runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"
OnClientClick='<%# Eval("ClassDesc", "return confirm(\"Delete {0}?\");") %>'>
</asp:LinkButton>
And that was it. Pretty simple.

1 comment: