言語

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) メソッドを必ず呼び出してください。

適用対象

こちらもご覧ください