This isn't too hard to accomplish using:
1) Template column.
2) <asp:LinkButton> control and it's OnClientClick property.
3) A little JavaScript
<asp:TemplateField>The trick is to use the OnClientClick property of the LinkButton control. OnClientClick is the property you use to specifiy the JavaScript to execute when the delete button is clicked. In this case we use the Eval() function to formulate our JavaScript and print our message on the confirm() box. The value of the column named 'Role' will be placed in the message, for example: Are you sure you want to delete role: asdf?
<ItemTemplate>
<asp:LinkButton
ID="lbtnGridDelete"
runat="server"
CausesValidation="false"
CommandName="Delete"
OnClientClick='<%# Eval("Role","return confirm(\"Are you sure you want to delete role: {0}?\")") %>'
Text="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
The resulting confirm box will look like this:
When the users presses the delete button, the client side code will run to produce the JavaScript confirm() box. If the user presses the 'OK' button then the post back will occur and the delete processing will execute.
No comments:
Post a Comment