BaseDataBoundControl.OnDataBound(EventArgs) 方法

定义

引发 DataBound 事件。Raises the DataBound event.

protected:
 virtual void OnDataBound(EventArgs ^ e);
protected virtual void OnDataBound (EventArgs e);
abstract member OnDataBound : EventArgs -> unit
override this.OnDataBound : EventArgs -> unit
Protected Overridable Sub OnDataBound (e As EventArgs)

参数

e
EventArgs

包含事件数据的 EventArgs 对象。An EventArgs object that contains the event data.

示例

下面的代码示例演示如何OnDataBound使用方法通过派生的数据绑定控件类DataBound引发事件。The following code example demonstrates how the OnDataBound method is used to raise the DataBound event by a derived data-bound control class. 使用GetData DataBoundPerformDataBinding方法将数据绑定到控件后, 数据绑定控件将引发事件, 以指示数据绑定已完成。After using the GetData and PerformDataBinding methods to bind data to the control, the data-bound control raises the DataBound event to signal that data binding is complete. 此代码示例是为DataBoundControl类提供的更大示例的一部分。This code example is part of a larger example provided for the DataBoundControl class.

protected override void PerformSelect() {            

   // Call OnDataBinding here if bound to a data source using the
   // DataSource property (instead of a DataSourceID), because the
   // databinding statement is evaluated before the call to GetData.       
    if (! IsBoundUsingDataSourceID) {
        OnDataBinding(EventArgs.Empty);
    }            
    
    // The GetData method retrieves the DataSourceView object from  
    // the IDataSource associated with the data-bound control.            
    GetData().Select(CreateDataSourceSelectArguments(), 
        OnDataSourceViewSelectCallback);
    
    // The PerformDataBinding method has completed.
    RequiresDataBinding = false;
    MarkAsDataBound();
    
    // Raise the DataBound event.
    OnDataBound(EventArgs.Empty);
}
Protected Overrides Sub PerformSelect()

    ' Call OnDataBinding here if bound to a data source using the 
    ' DataSource property (instead of a DataSourceID) because the 
    ' data-binding statement is evaluated before the call to GetData.
    If Not IsBoundUsingDataSourceID Then
        OnDataBinding(EventArgs.Empty)
    End If

    ' The GetData method retrieves the DataSourceView object from the 
    ' IDataSource associated with the data-bound control.            
    GetData().Select(CreateDataSourceSelectArguments(), _
        AddressOf OnDataSourceViewSelectCallback)

    ' The PerformDataBinding method has completed.
    RequiresDataBinding = False
    MarkAsDataBound()

    ' Raise the DataBound event.
        OnDataBound(EventArgs.Empty)

End Sub

注解

此方法通知服务器控件任何与该控件关联的数据绑定逻辑都已完成。This method notifies a server control that any data binding logic associated with the control has completed.

重要

DataBind方法在派生自BaseDataBoundControl的所有控件上是密封的。The DataBind method is sealed on all controls derived from BaseDataBoundControl. 数据绑定控件应重写PerformDataBinding , 而不DataBind是绑定数据的方法。Data-bound controls should override PerformDataBinding instead of the DataBind method to bind data. 如果DataBind重写, 则OnDataBindingOnDataBound事件将按顺序引发。If DataBind is overridden, the OnDataBinding and OnDataBound events are raised out of order.

引发事件时,将通过委托调用事件处理程序。Raising an event invokes the event handler through a delegate. 有关详细信息, 请参阅处理和引发事件For more information, see Handling and Raising Events.

OnDataBound 方法还允许派生类对事件进行处理而不必附加委托。The OnDataBound method also allows derived classes to handle the event without attaching a delegate. 这是在派生类中处理事件的首选技术。This is the preferred technique for handling the event in a derived class.

继承者说明

当在OnDataBound(EventArgs)派生类中重写时, 请确保调用基类的OnDataBound(EventArgs)方法, 以便注册的委托接收事件。When overriding OnDataBound(EventArgs) in a derived class, be sure to call the base class' OnDataBound(EventArgs) method so that registered delegates receive the event.

适用于

另请参阅