2.20. Adding a Delete Confirmation Pop-Up
Problem
You want to add to a GridView
row a confirmation pop-up that appears whenever a user tries to delete a row in the GridView
.
Solution
Add a Select button to each row of the GridView
and a Delete button below the GridView
. Whenever the Delete button is clicked, execute some client-side script that displays the confirmation pop-up, followed by some server-side code that performs the actual deletion.
In the .aspx file:
Create an extra button column in the
GridView
to display a Select button.Add a Delete button below the
GridView
.
In the code-behind class for the page, use the .NET language of your choice to:
Register the client-side script to be executed when the Delete button is clicked.
Add an attribute to the Delete button that calls the delete script when the Delete button is clicked.
Figure 2-22 shows a GridView
with this solution implemented. Examples 2-54, 2-55 through 2-56 show the .aspx and code-behind files for the application that produces this result.
Figure 2-22. Confirmation pop-up before deletion in a GridView output
Discussion
To display a confirmation pop-up when a user attempts to delete a row in a data table, you create a GridView
in the same way you have done throughout this chapter, except that you add a button column to allow for row selection. Setting the ButtonType
to "Link
" outputs a hyperlink for selecting the row. (The ...
Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.