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

注解

PerformDataBinding控件适配器附加到派生自 DataBoundControl 类的DataBoundControl.PerformDataBinding控件时DataBoundControlAdapter,将调用 方法来代替 方法。

通常,重写 DataBoundControl.PerformDataBinding 会循环访问数据,在必要时创建不同的名称和值,并将其保存到内部集合。 通常, RenderContents 或类似的 DataBoundControl 方法会填充该内部集合中的用户界面或子控件。

继承者说明

PerformDataBinding(IEnumerable)当目标浏览器需要专用绑定逻辑时重写 方法 - 例如,当项名称的构造方式必须不同于控件的常规用法时。

PerformDataBinding(IEnumerable) 方法调用 PerformDataBinding(IEnumerable)。 仅当需要 的数据绑定功能时,DataBoundControl才应调用PerformDataBinding(IEnumerable)基方法。

适用于

另请参阅