DataBoundControl.GetData 方法

定義

擷取 DataSourceView 物件,資料繫結控制項會用來執行資料作業。

protected:
 virtual System::Web::UI::DataSourceView ^ GetData();
protected virtual System.Web.UI.DataSourceView GetData ();
abstract member GetData : unit -> System.Web.UI.DataSourceView
override this.GetData : unit -> System.Web.UI.DataSourceView
Protected Overridable Function GetData () As DataSourceView

傳回

DataSourceView,資料繫結控制項將其用於執行資料作業。 如果設定 DataMember 屬性,則會傳回特定的具名 DataSourceView,否則會傳回預設 DataSourceView

例外狀況

會同時設定 DataSourceDataSourceID 屬性。

-或-

會設定 DataMember 屬性,但具有該名稱的 DataSourceView 物件並不存在。

範例

下列程式碼範例示範如何 GetData 呼叫 方法,以 DataSourceView 從相關聯的資料來源控制項擷取物件,並 Select 呼叫 方法來擷取資料。 此程式碼範例是針對 類別提供的較大範例的 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

備註

GetData方法會 DataSourceView 藉由呼叫 GetDataSource 方法,從相關聯的資料來源控制項擷取 物件。 DataSource如果使用 屬性來識別資料來源,則會建立預設 DataSourceView 物件。

適用於

另請參閱