BaseDataBoundControl.RequiresDataBinding 属性

定义

获取或设置一个值,该值指示是否应调用 DataBind() 方法。Gets or sets a value indicating whether the DataBind() method should be called.

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

属性值

true如果在呈现控件之前应调用数据绑定控件的DataBind()方法, 则返回值为; 否则, 值为falseThe returned value is true if the data-bound control's DataBind() method should be called before the control is rendered; otherwise, the value is false.

示例

下面的代码示例演示派生的RequiresDataBinding数据绑定控件类如何使用属性。The following code example demonstrates how the RequiresDataBinding property 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 this property during the current page's lifecycle. 此代码示例是为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

注解

如果将RequiresDataBinding属性设置为true , 则当数据绑定控件已经开始向页面呈现其输出时, 当前 HTTP 请求不是回调, DataSourceID并且你正在使用属性将数据源控件标识为绑定到, DataBind将立即调用方法。If you set the RequiresDataBinding property to true when the data-bound control has already begun to render its output to the page, the current HTTP request is not a callback, and you are using the DataSourceID property to identify the data source control to bind to, the DataBind method is called immediately. 在这种情况下RequiresDataBinding , 属性实际不会设置true为。In this case, the RequiresDataBinding property is not actually set to true.

适用于

另请参阅