BaseDataBoundControl.RequiresDataBinding 屬性

定義

取得或設定值,指出是否應該呼叫 DataBind() 方法。

protected:
 property bool RequiresDataBinding { bool get(); void set(bool value); };
protected bool RequiresDataBinding { get; set; }
member this.RequiresDataBinding : bool with get, set
Protected Property RequiresDataBinding As Boolean

屬性值

Boolean

如果資料繫結控制項的 DataBind() 方法應該在轉譯控制項之前呼叫,則傳回的值 truefalse ,否則值為 。

範例

下列程式碼範例示範衍生資料繫結控制項類別如何使用 RequiresDataBinding 屬性。 方法擷 GetData 取資料並系結至 具有 PerformDataBinding 方法的控制項之後, RequiresDataBinding 屬性會設定為 false ,並 MarkAsDataBound 呼叫 方法以表示控制項已完成系結,而且在目前頁面的生命週期期間不再需要這個屬性。 此程式碼範例是提供給 類別之較大範例的 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

備註

如果您在資料繫結控制項已開始將其輸出轉譯至頁面時,將 屬性 true 設定 RequiresDataBinding 為 ,則目前的 HTTP 要求不是回呼,而且您正在使用 DataSourceID 屬性來識別要系結的資料來源控制項, DataBind 則會立即呼叫 方法。 在此情況下, RequiresDataBinding 屬性實際上不會設定為 true

適用於

另請參閱