This documentation is archived and is not being maintained.

ObjectDataSourceMethodEventHandler Delegate

Represents the method that will handle the Selecting, Updating, Inserting, or Deleting event of the ObjectDataSource control.

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

public delegate void ObjectDataSourceMethodEventHandler(
	Object^ sender, 
	ObjectDataSourceMethodEventArgs^ e
)

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 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.

No code example is currently available or this language may not be supported.

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.

No code example is currently available or this language may not be supported.

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
Show: