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

返回的值是 true ,如果在呈现控件之前应调用数据绑定控件 DataBind() 的方法,则返回的值为 false

示例

下面的代码示例演示了派生数据绑定控件类如何使用 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

适用于

另请参阅