ObjectDataSourceMethodEventArgs Class
Provides data for the Inserting, Updating, and Deleting events of the ObjectDataSource control.
System::EventArgs
System.ComponentModel::CancelEventArgs
System.Web.UI.WebControls::ObjectDataSourceMethodEventArgs
System.Web.UI.WebControls::ObjectDataSourceSelectingEventArgs
Assembly: System.Web (in System.Web.dll)
The ObjectDataSourceMethodEventArgs type exposes the following members.
Name | Description | |
---|---|---|
![]() | ObjectDataSourceMethodEventArgs | Initializes a new instance of the ObjectDataSourceMethodEventArgs class using the specified input parameters collection. |
Name | Description | |
---|---|---|
![]() | Cancel | Gets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.) |
![]() | InputParameters | Gets a collection that contains business object method parameters and their values. |
Name | Description | |
---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The ObjectDataSourceMethodEventArgs class is used in the OnSelecting, OnUpdating, OnInserting, and OnDeleting methods to provide access to input parameters that are passed to the Select, Update, Delete, and Insert methods of the ObjectDataSource control. These parameters are accessed using the InputParameters property. By adding a delegate to handle the Selecting, Updating, Inserting, or Deleting event, you can examine and manipulate the values of the parameters and perform any additional preprocessing that is required. Any changes to the parameters in this dictionary will affect which method overload is called for the operation. When the DataObjectTypeName property of the ObjectDataSource control is set, you can only modify the data object properties for the items in this dictionary; you cannot add or remove parameters. For more information, see Delete.
The ObjectDataSource control exposes many events that you can handle to work with the underlying business object at various times in its life cycle. The following table lists the events and associated EventArgs classes and event handler delegates.
Event | EventArgs class | EventHandler delegate |
---|---|---|
Occurs immediately before the instance of the business object is created. | ||
Occurs immediately after the instance of the business object is created. | ||
Occurs before the data is retrieved. | ||
Inserting, Updating, and Deleting. Occur before an insert, update, or delete operation is performed. | ObjectDataSourceMethodEventArgs | |
Occurs after the data is retrieved. | ||
Inserted, Updated, and Deleted. Occur after the insert, update, or delete operation is completed. | ||
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 DetailsView control to insert data. The second code example provides an example middle-tier business object that is used by the first code example.
The following code example demonstrates how to use an ObjectDataSource control with a business object and a DetailsView control to insert data. The DetailsView initially displays a new NorthwindEmployee record, along with an automatically generated Insert button. After you enter data into the fields of the DetailsView control, click the Insert button, and the InsertMethod property will identify which method performs the Insert action.
In this example, the UpdateEmployeeInfo method is used to perform an insert; however, it requires a NorthwindEmployee parameter to insert the data. For this reason, the collection of strings that the DetailsView control passes automatically is not sufficient. The NorthwindEmployeeInserting delegate is an ObjectDataSourceMethodEventHandler object that handles the Inserting event and enables you to manipulate the input parameters before the Insert operation proceeds. Because the UpdateEmployeeInfo method requires a NorthwindEmployee object as a parameter, one is created using the collection of strings and is added to the InputParameters collection.
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, which is a stateless class that encapsulates business logic.
The NorthwindEmployee class, which 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 available with Microsoft SQL Server and Microsoft Access. For a complete working example, use these classes by placing them in the App_Code directory under the application root or by compiling them and placing the resulting DLL in the Bin directory. The UpdateEmployeeInfo method is not completely implemented, so you will not insert data into the Northwind Traders database when you experiment with this example.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.