共用方式為


DataBoundControl.MarkAsDataBound 方法

定義

將檢視狀態中的控制項狀態設為已成功繫結至資料。

protected:
 void MarkAsDataBound();
protected void MarkAsDataBound ();
member this.MarkAsDataBound : unit -> unit
Protected Sub MarkAsDataBound ()

範例

下列程式碼範例示範衍生資料繫結控制項類別如何使用 MarkAsDataBound 方法。 方法擷 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

備註

資料繫結控制項會在檢視狀態中維護值,指出它目前是否系結至資料。 方法會將 MarkAsDataBound 值設定為 true

適用於

另請參閱