This documentation is archived and is not being maintained.

ObjectDataSource.Delete Method

Performs a delete operation by calling the method that is identified by the DeleteMethod property with any parameters that are in the DeleteParameters collection.

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

public int Delete ()
public int Delete ()
public function Delete () : int
Not applicable.

Return Value

A value that represents the number of rows deleted from the underlying data storage, if the AffectedRows property of the ObjectDataSourceStatusEventArgs is set in the Deleted event; otherwise, -1.

Before the Delete operation is performed, the OnDeleting method is called to raise the Deleting event. You can handle the Deleting event to examine the values of the parameters and to perform any preprocessing before a Delete operation. To perform a delete operation, the ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the TypeName property. It then calls the method that is identified by the DeleteMethod property, using any associated DeleteParameters properties. If the deletion parameters come from an associated data-bound control, the name of the parameters is created according to the OldValuesParameterFormatString property. After the Delete operation completes, the OnDeleted method is called to raise the Deleted event. You can handle the Deleted event to examine any return values, output parameters, and exceptions, and to perform any post-processing.


If you are not familiar with the Data Access features in ASP.NET 2.0, you should read some of these topics before continuing:

The Delete method delegates to the Delete method of the ObjectDataSourceView object that is associated with the ObjectDataSource control.

Data-Bound Controls

When the ObjectDataSource control is associated with a data-bound control, such as the GridView control, it is not necessary to call the Delete method from page code. The Delete method is invoked directly by the data-bound control instead.

For more information about parameter merging, object lifetime, and method resolution, see DeleteMethod.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0