ObjectDataSourceMethodEventHandler Delegate
Represents the method that will handle the Selecting, Updating, Inserting, or Deleting event of the ObjectDataSource control.
Assembly: System.Web (in System.Web.dll)
type ObjectDataSourceMethodEventHandler = delegate of sender:Object * e:ObjectDataSourceMethodEventArgs -> unit
Parameters
- sender
-
Type:
System.Object
The source of the event, the ObjectDataSource.
- e
-
Type:
System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs
An ObjectDataSourceMethodEventArgs that contains the event data.
The Selecting, Updating, Inserting, or Deleting event of the ObjectDataSource control allows you to manipulate the parameters that are used to determine the method that is called by the ObjectDataSource control. For more information, see ObjectDataSourceMethodEventArgs.
When you create an ObjectDataSourceMethodEventHandler 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 NIB: Consuming Events.
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. Initially, the DetailsView 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 the example middle-tier business object that the preceding code example uses. The code example consists of the following two basic classes and one additional class:
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.
An additional NorthwindDataException class, which is provided as a convenience.
This set of example classes works with the Northwind Traders database, which is an example database that is 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 into a library 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.
Available since 2.0