语言

BaseDataBoundControl.OnDataBound(EventArgs) 方法

定义

引发 DataBound 事件。

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包含事件数据的对象。

示例

下面的代码示例演示如何 OnDataBound 使用该方法通过派生的数据绑定控件类引发 DataBound 事件。 使用 GetData 和 PerformDataBinding 方法将数据绑定到控件后,数据绑定控件将引发 DataBound 事件以指示数据绑定已完成。 该代码示例是 DataBoundControl 类中的一个较大示例的一部分。

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

注解

此方法通知服务器控件与控件关联的任何数据绑定逻辑已完成。

Important

该方法 DataBind 在派生自 BaseDataBoundControl的所有控件上密封。 数据绑定控件应替代 PerformDataBinding 而不是 DataBind 绑定数据的方法。 如果 DataBind 被重写,则会 OnDataBinding 按顺序引发事件 OnDataBound 。

引发事件会通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件。

该方法 OnDataBound 还允许派生类在不附加委托的情况下处理事件。 这是处理派生类中的事件的首选技术。

继承者说明

在派生类中重写 OnDataBound(EventArgs) 时,请务必调用基类 OnDataBound(EventArgs) 的方法,以便已注册的委托接收事件。

适用于

另请参阅