GridViewDeletedEventHandler Delegate
Represents the method that handles the RowDeleted event of a GridView control.
Assembly: System.Web (in System.Web.dll)
'Declaration Public Delegate Sub GridViewDeletedEventHandler ( _ sender As Object, _ e As GridViewDeletedEventArgs _ ) 'Usage Dim instance As New GridViewDeletedEventHandler(AddressOf HandlerMethod)
Parameters
- sender
- Type: System.Object
The source of the event.
- e
- Type: System.Web.UI.WebControls.GridViewDeletedEventArgs
A GridViewDeletedEventArgs that contains the event data.
The GridView control raises the RowDeleted event when a Delete button (a button with its CommandName property set to "Delete") within the control is clicked, but after the GridView control deletes the record. This allows you to provide an event-handling method that performs a custom routine, such as checking the results of a delete operation, whenever this event occurs.
When you create a GridViewDeletedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.
The following example demonstrates how to programmatically add a GridViewDeletedEventHandler delegate to the RowDeleted event of a GridView control.
<%@ Page language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new GridView control. Dim customersGridView As New GridView() ' Set the GridView control's properties. customersGridView.ID = "CustomersGridView" customersGridView.DataSourceID = "CustomersSqlDataSource" customersGridView.AutoGenerateColumns = True customersGridView.AutoGenerateDeleteButton = True Dim keyArray() As String = {"CustomerID"} customersGridView.DataKeyNames = keyArray ' Programmatically register the event-handling method ' for the RowDeleted event of the GridView control. AddHandler customersGridView.RowDeleted, AddressOf CustomersGridView_RowDeleted ' Add the GridView control to the Controls collection ' of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(customersGridView) End Sub Sub CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs) ' Display whether the delete operation succeeded. If e.Exception Is Nothing Then Message.Text = "Row deleted successfully." Else Message.Text = "An error occurred while attempting to deleting the row." e.ExceptionHandled = True End If End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridViewDeletedEventHandler Example</title> </head> <body> <form id="form1" runat="server"> <h3>GridViewDeletedEventHandler Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <asp:placeholder id="GridViewPlaceHolder" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
The following example demonstrates how to declaratively add a GridViewDeletedEventHandler delegate to the RowDeleted event of a GridView control.
<%@ Page language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Sub CustomersGridView_RowDeleted(sender As Object, e As GridViewDeletedEventArgs) ' Display whether the delete operation succeeded. If e.Exception Is Nothing Then Message.Text = "Row deleted successfully." Else Message.Text = "An error occurred while attempting to delete the row." e.ExceptionHandled = True End If End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridView RowDeleted Example</title> </head> <body> <form id="form1" runat="server"> <h3>GridView RowDeleted Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogeneratedeletebutton="true" datakeynames="CustomerID" onrowdeleted="CustomersGridView_RowDeleted" runat="server"> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.