ObjectDataSource.Delete ObjectDataSource.Delete ObjectDataSource.Delete ObjectDataSource.Delete Method


通过用 DeleteMethod 集合中的所有参数调用由 DeleteParameters 属性标识的方法,执行删除操作。Performs a delete operation by calling the method that is identified by the DeleteMethod property with any parameters that are in the DeleteParameters collection.

 int Delete();
public int Delete ();
member this.Delete : unit -> int
Public Function Delete () As Integer


如果在 AffectedRows 事件中设置了 ObjectDataSourceStatusEventArgsDeleted 属性,则为表示从基础数据存储中删除的行数的值,否则为 -1。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.


在执行OnDeleting操作之前, 将调用方法来引发Deleting事件。 DeleteBefore the Delete operation is performed, the OnDeleting method is called to raise the Deleting event. 您可以处理Deleting事件以检查参数的值并在Delete操作之前执行任何预处理。You can handle the Deleting event to examine the values of the parameters and to perform any preprocessing before a Delete operation. 若要执行删除操作, ObjectDataSourceView对象使用反射来创建TypeName由属性标识的对象的实例。To perform a delete operation, the ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the TypeName property. 然后, 它使用任意关联DeleteMethod DeleteParameters的属性调用由属性标识的方法。It then calls the method that is identified by the DeleteMethod property, using any associated DeleteParameters properties. 如果删除参数来自关联的数据绑定控件, 则根据OldValuesParameterFormatString属性创建参数的名称。If the deletion parameters come from an associated data-bound control, the name of the parameters is created according to the OldValuesParameterFormatString property. 操作完成后OnDeleted , 调用方法来引发Deleted事件。 DeleteAfter the Delete operation completes, the OnDeleted method is called to raise the Deleted event. 您可以处理Deleted事件以检查任何返回值、输出参数和异常, 并执行任何后续处理。You can handle the Deleted event to examine any return values, output parameters, and exceptions, and to perform any post-processing.

方法委托ObjectDataSourceView Delete给与ObjectDataSource控件相关联的对象的方法。 DeleteThe Delete method delegates to the Delete method of the ObjectDataSourceView object that is associated with the ObjectDataSource control.

数据绑定控件Data-Bound Controls

当控件与数据绑定控件 (如GridView控件) 关联时, Delete无需从页代码中调用方法。 ObjectDataSourceWhen 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. 改为直接通过数据绑定控件调用方法。DeleteThe Delete method is invoked directly by the data-bound control instead.

有关参数合并、对象生存期和方法解析的详细信息, 请参阅DeleteMethodFor more information about parameter merging, object lifetime, and method resolution, see DeleteMethod.