แก้ไข

แชร์ผ่าน


DataBoundControlAdapter.PerformDataBinding(IEnumerable) Method

Definition

Binds the data in the data source of the associated DataBoundControl object to the control adapter.

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)

Parameters

data
IEnumerable

An IEnumerable of Object to be bound to the derived DataBoundControl.

Examples

The following code example shows how to override the PerformDataBinding collection to save the data source to a one-dimensional ArrayList object and add row separators. It also shows how to override the RenderContents method to render the ArrayList as a list of fields separated by <br /> tags.

// 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

Remarks

The PerformDataBinding method is called in place of the DataBoundControl.PerformDataBinding method when a DataBoundControlAdapter control adapter is attached to a control derived from the DataBoundControl class.

Typically, an override of DataBoundControl.PerformDataBinding iterates through data, creating distinct names and values when necessary, and saves it to an internal collection. Usually, RenderContents or a similar method of the DataBoundControl will populate the user interface or child controls from that internal collection.

Notes to Inheritors

Override the PerformDataBinding(IEnumerable) method when specialized binding logic is required for the target browser - for example, when item names must be constructed differently than for the general usage of the control.

The PerformDataBinding(IEnumerable) base method calls PerformDataBinding(IEnumerable). You should call the PerformDataBinding(IEnumerable) base method only if you require the data binding functionality of the DataBoundControl.

Applies to

See also