DataBoundControl.MarkAsDataBound 方法

定义

将视图状态中的控件状态设置为成功绑定到数据。Sets the state of the control in view state as successfully bound to data.

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

示例

下面的代码示例演示派生的MarkAsDataBound数据绑定控件类如何使用方法。The following code example demonstrates how the MarkAsDataBound method is used by a derived data-bound control class. GetData RequiresDataBinding false使用方法检索数据并将其绑定到控件后, 属性将设置为, 并MarkAsDataBound调用方法以指示控件已完成绑定, 而不再PerformDataBinding在当前页的生命周期中需要它。After data is retrieved by the GetData method and bound to the control with the PerformDataBinding method, the RequiresDataBinding property is set to false and the MarkAsDataBound method is called to signal that the control has completed binding and no longer requires it during the current page's life cycle. 此代码示例是为DataBoundControl类提供的更大示例的一部分。This code example is part of a larger example provided for the DataBoundControl class.

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

注解

数据绑定控件在视图状态中维护一个值, 该值指示当前是否已绑定到数据。The data-bound control maintains a value in view state that indicates whether it is currently bound to data. 方法将值设置为trueMarkAsDataBoundThe MarkAsDataBound method sets the value to true.

适用于

另请参阅