This documentation is archived and is not being maintained.

ObjectDataSourceStatusEventHandler Delegate

Represents the method that will handle the Selected, Updated, Inserted, and Deleted events of the ObjectDataSource control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Public Delegate Sub ObjectDataSourceStatusEventHandler ( _
	sender As Object, _
	e As ObjectDataSourceStatusEventArgs _
Dim instance As New ObjectDataSourceStatusEventHandler(AddressOf HandlerMethod)


Type: System.Object

The source of the event, the ObjectDataSource control.

Type: System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs

An ObjectDataSourceStatusEventArgs that contains the event data.

When you create an ObjectDataSourceStatusEventHandler 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 Consuming Events.

The following code example demonstrates how to use an ObjectDataSource control with a business object and a GridView control to delete data. The GridView initially displays a set of all employees, using the method that is specified by the SelectMethod property to retrieve the data from the EmployeeLogic object. Because the AutoGenerateDeleteButton property is set to true, the GridView control automatically displays a Delete button.

If you click the Delete button, the Delete action is performed using the method that is specified by the DeleteMethod property and any parameters that are specified in the DeleteParameters collection.

In this code example, some preprocessing and post-processing steps are also performed. The NorthwindEmployeeDeleting delegate is called to handle the Deleting event before the Delete action is performed, and the NorthwindEmployeeDeleted delegate is called to handle the Deleted event after the Delete action has completed, to perform exception handling. In this example, if a NorthwindDataException is thrown, it is handled by this delegate.

To examine the implementation of the EmployeeLogic middle-tier business object that this code example uses, see the class overview in ObjectDataSourceStatusEventArgs.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Import namespace="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<script runat="server">
' Called before a Delete operation. 
    Private Sub NorthwindEmployeeDeleting(ByVal source As Object, ByVal e As ObjectDataSourceMethodEventArgs)

        ' The GridView passes the ID of the employee 
        ' to be deleted. However, the business object, EmployeeLogic, 
        ' requires a NorthwindEmployee parameter, named "ne". Create 
        ' it now and add it to the parameters collection. 
        Dim paramsFromPage As IDictionary = e.InputParameters

        If Not paramsFromPage("EmpID") Is Nothing Then 

            Dim ne As New NorthwindEmployee(paramsFromPage("EmpID").ToString())
            ' Remove the old EmpID parameter.
            paramsFromPage.Add("ne", ne)

        End If 
    End Sub ' NorthwindEmployeeDeleting

    ' Called after a Delete operation. 
    Private Sub NorthwindEmployeeDeleted(ByVal source As Object, ByVal e As ObjectDataSourceStatusEventArgs)
        ' Handle the Exception if it is a NorthwindDataException. 
        If Not e.Exception Is Nothing Then 

            ' Handle the specific exception type. The ObjectDataSource wraps 
            ' any Exceptions in a TargetInvokationException wrapper, so 
            ' check the InnerException property for the expected Exception types. 
            If e.Exception.InnerException.GetType().Equals(GetType(NorthwindDataException)) Then

                Label1.Text = e.Exception.InnerException.Message
                ' Because the exception is handled, there is 
                ' no reason to throw it.
                e.ExceptionHandled = True 

            End If 
        End If 
    End Sub ' NorthwindEmployeeDeleted
<html xmlns="" >
    <title>ObjectDataSource - VB Example</title>
    <form id="Form1" method="post" runat="server">

            <asp:boundfield headertext="EmpID" datafield="EmpID" />
            <asp:boundfield headertext="First Name" datafield="FirstName" />
            <asp:boundfield headertext="Last Name" datafield="LastName" />

            <asp:parameter name="EmpID" type="Int32" />

        <asp:label id="Label1" runat="server" />


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.

.NET Framework

Supported in: 3.5, 3.0, 2.0