ObjectDataSourceStatusEventArgs Class
Assembly: System.Web (in system.web.dll)
The ObjectDataSourceStatusEventArgs class is used in the OnSelected, OnUpdated, OnInserted, and OnDeleted methods to provide access to output parameters, return values, and exceptions that are thrown by the method that is called by the ObjectDataSource control. These are accessed by the OutputParameters, ReturnValue, and Exception properties, respectively. By adding a delegate to handle the Selected, Updated, Inserted, or Deleted events, you can examine this data and perform any additional post processing that is required.
The ObjectDataSource control exposes many events that you can handle to work with the underlying business object at various times in its lifecycle. The following table lists the events and the associated EventArgs classes and event handler delegates.
| Event | EventArgs | EventHandler |
|---|---|---|
| Occurs immediately before the instance of the business object is created. | ||
| Occurs immediately after the instance of the business object is created. | ObjectDataSourceEventArgs | ObjectDataSourceObjectEventHandler |
| Occurs before the data is retrieved. | ||
| Inserting, Updating, and Deleting. Occur before an insert, update, or delete operation is performed. | ||
| Selected. Occurs after the data is retrieved. | ObjectDataSourceStatusEventArgs | |
| Inserted, Updated, and Deleted. Occur after the insert, update, or delete operation is completed. | ObjectDataSourceStatusEventArgs | ObjectDataSourceStatusEventHandler |
| Occurs before a business object is destroyed. |
This section contains two code examples. The first code example demonstrates how to use an ObjectDataSource control with a business object and a GridView control to delete data. The second code example provides an example middle-tier business object that the first code example uses.
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, one parameter is specified in the DeleteParameters collection that corresponds to the employee ID. This is because although the ID is included in the Columns collection as a BoundField object, it will be passed as a string to the ObjectDataSource control. By adding it explicitly to the DeleteParameters collection with a Type property set to the Int32 value, it will pass correctly by the ObjectDataSource to the method as an integer, rather than as string.
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 handle any exceptions that might have occurred. The NorthwindEmployeeDeleted delegate accesses possible exceptions that are thrown by the business object that is using the ObjectDataSourceStatusEventArgs object. In this example, if a NorthwindDataException is thrown, it is handled by this delegate.
The following code example provides an example middle-tier business object that the preceding code example uses. The following list describes the two major classes that are defined in the code example:
-
The EmployeeLogic class is a class that does not maintain state and encapsulates business logic.
-
The NorthwindEmployee class is a model class that contains only the basic functionality that is required to load and persist data from the data tier.
In addition, a NorthwindDataException class is provided as a convenience.
This set of example classes uses the Northwind Traders database, which is an example database that is available with Microsoft SQL Server and Microsoft Access. For a complete working example, you must compile this code as a library, and then use these classes from an ASP page. The ASP page that is provided in the preceding example is configured to work with this class library. The UpdateEmployeeInfo method is not completely implemented, so you will not insert data into the Northwind Traders database when you experiment with this example.
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.