BaseDataBoundControl.IsBoundUsingDataSourceID 属性

定义

获取指示是否设置 DataSourceID 属性的值。

protected:
 property bool IsBoundUsingDataSourceID { bool get(); };
protected bool IsBoundUsingDataSourceID { get; }
member this.IsBoundUsingDataSourceID : bool
Protected ReadOnly Property IsBoundUsingDataSourceID As Boolean

属性值

true如果DataSourceID属性设置为除 以外的Empty值,则返回值;否则,该值为 false

示例

下面的代码示例演示派生的数据绑定控件类如何使用 IsBoundUsingDataSourceID 属性。 属性 IsBoundUsingDataSourceID 用于在方法实现中 PerformSelect 确定是否 DataBinding 应引发事件。 此代码示例是为 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

注解

、、 和 等GridView控件使用 IsBoundUsingDataSourceID 属性来确定数据绑定控件是否绑定到 ASP.NET 2.0 数据源控件,如 ObjectDataSourceSqlDataSourceMenuFormViewDetailsView

适用于

另请参阅