共用方式為


DataBoundControlAdapter.PerformDataBinding(IEnumerable) 方法

定義

將關聯 DataBoundControl 物件資料來源中的資料繫結至控制項配置器。

protected public:
 virtual void PerformDataBinding(System::Collections::IEnumerable ^ data);
protected internal virtual void PerformDataBinding (System.Collections.IEnumerable data);
abstract member PerformDataBinding : System.Collections.IEnumerable -> unit
override this.PerformDataBinding : System.Collections.IEnumerable -> unit
Protected Friend Overridable Sub PerformDataBinding (data As IEnumerable)

參數

data
IEnumerable

將繫結至衍生 IEnumerableObjectDataBoundControl

範例

下列程式碼範例示範如何覆寫集合, PerformDataBinding 以將資料來源儲存至一維 ArrayList 物件,並新增資料列分隔符號。 它也會示範如何覆寫 RenderContents 方法,以轉譯 ArrayList 為以 <br /> 標記分隔的欄位清單。

// One-dimensional list for the grid data.
ArrayList dataArray = new ArrayList();

// Copy grid data to one-dimensional list, add row separators.
protected override void PerformDataBinding(IEnumerable data)
{
    IEnumerator dataSourceEnumerator = data.GetEnumerator();

    // Iterate through the table rows.
    while (dataSourceEnumerator.MoveNext())
    {
        // Add the next data row to the ArrayList.
        dataArray.AddRange(
            ((DataRowView)dataSourceEnumerator.Current).Row.ItemArray);

        // Add a separator to the ArrayList.
        dataArray.Add("----------");
    }
}

// Render the data source as a one-dimensional list.
protected override void RenderContents(
    System.Web.UI.HtmlTextWriter writer)
{
    // Render the data list.
    for( int col=0; col<dataArray.Count;col++)
    {
        writer.Write(dataArray[col]);
        writer.WriteBreak();
    }
}
' One-dimensional list for the grid data.
Private dataArray As New ArrayList()

' Copy grid data to one-dimensional list, add row separators.
Protected Overrides Sub PerformDataBinding(ByVal data As IEnumerable)

    Dim dataSourceEnumerator As IEnumerator = data.GetEnumerator()

    ' Iterate through the table rows.
    While dataSourceEnumerator.MoveNext()

        ' Add the next data row to the ArrayList.
        dataArray.AddRange(CType(dataSourceEnumerator.Current, _
                                DataRowView).Row.ItemArray)

        ' Add a separator to the ArrayList.
        dataArray.Add("----------")
    End While
End Sub

' Render the data source as a one-dimensional list.
Protected Overrides Sub RenderContents( _
    ByVal writer As System.Web.UI.HtmlTextWriter)

    ' Render the data list.
    Dim col As Integer
    For col = 0 To dataArray.Count - 1
        writer.Write(dataArray(col))
        writer.WriteBreak()
    Next col
End Sub

備註

當控制項配接器附加至衍生自 DataBoundControl 類別的 DataBoundControl.PerformDataBinding 控制項時 DataBoundControlAdapter ,會 PerformDataBinding 呼叫 方法來取代 方法。

一般而言,覆寫 DataBoundControl.PerformDataBinding 會逐一查看資料、在必要時建立不同的名稱和值,並將它儲存至內部集合。 通常, RenderContents 或類似的 方法 DataBoundControl 會從該內部集合填入使用者介面或子控制項。

給繼承者的注意事項

PerformDataBinding(IEnumerable)當目標瀏覽器需要特製化系結邏輯時覆寫 方法,例如,專案名稱的建構方式必須與控制項的一般用法不同。

PerformDataBinding(IEnumerable) 底方法會呼叫 PerformDataBinding(IEnumerable) 。 只有在需要 的資料系結功能 DataBoundControl 時,才應該呼叫 PerformDataBinding(IEnumerable) 基底方法。

適用於

另請參閱