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 事件。 使用 GetDataPerformDataBinding 方法將資料系結至 控制項之後,資料系結控制項會 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

備註

這個方法會通知伺服器控制項與控制項相關聯的任何資料系結邏輯都已完成。

重要

方法 DataBind 會在衍生自 BaseDataBoundControl 的所有控制項上密封。 資料繫結控制項應該覆寫 PerformDataBinding ,而不是 DataBind 系結資料的方法。 如果 DataBind 已覆寫, OnDataBinding 則會依序引發 和 OnDataBound 事件。

引發事件會透過委派叫用此事件處理常式。 如需詳細資訊,請參閱 處理和引發事件

OnDataBound 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。

給繼承者的注意事項

在衍生類別中覆 OnDataBound(EventArgs) 寫時,請務必呼叫基類的 OnDataBound(EventArgs) 方法,讓已註冊的委派接收事件。

適用於

另請參閱