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.

适用于

另请参阅