BaseDataBoundControl.OnDataBound(EventArgs) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
引發 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)
參數
範例
以下程式碼範例展示了如何透過衍生的資料綁定控制類別來使用該 OnDataBound 方法來引發 DataBound 事件。 在使用 and 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
備註
此方法會通知伺服器控制項,任何與該控制項相關的資料綁定邏輯已完成。
Important
DataBind該方法在所有由 BaseDataBoundControl衍生出的控制項上都封閉。 資料綁定控制項應該覆蓋 PerformDataBinding ,而不是綁 DataBind 定資料的方法。 若 DataBind 被覆寫, OnDataBinding 則 和 OnDataBound 事件會被打亂順序。
發起事件會透過代理呼叫事件處理者。 欲了解更多資訊,請參閱 處理與提升事件。
此 OnDataBound 方法也允許衍生類別在不附加代理的情況下處理事件。 這是在衍生類別中處理事件的首選技術。
給繼承者的注意事項
在導出類別中覆寫 OnDataBound(EventArgs) 時,務必呼叫基底類別的方法 OnDataBound(EventArgs) ,讓註冊代理接收事件。