Export (0) Print
Expand All

DataBoundControl.PerformDataBinding Method

When overridden in a derived class, binds data from the data source to the control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Protected Friend Overridable Sub PerformDataBinding ( _
	data As IEnumerable _


Type: System.Collections.IEnumerable

The IEnumerable list of data returned from a PerformSelect method call.

Implement this method instead of the DataBind method when you derive a data-bound control from the DataBoundControl class. Placing your control's data-binding logic in PerformDataBinding enables you to avoid the DataBinding and DataBound events being raised in the wrong order.

While the base DataBoundControl class provides no specific implementation for this method, the PerformDataBinding method is called by the PerformSelect method to bind the values of any user interface (UI) controls to the data that is retrieved by the PerformSelect method.

The following code example demonstrates how to implement the PerformDataBinding method in a class derived from DataBoundControl. The TextBoxSet control creates a TextBox control for each data item it is bound to. This code example is part of a larger example provided for the DataBoundControl class.

Protected Overrides Sub PerformDataBinding(ByVal retrievedData As IEnumerable)

        ' If the data is retrieved from an IDataSource as an IEnumerable  
        ' collection, attempt to bind its values to a set of TextBox controls. 
        If Not (retrievedData Is Nothing) Then 

            Dim dataItem As Object 
            For Each dataItem In retrievedData

                Dim box As New TextBox()

                ' The dataItem is not just a string, but potentially 
                ' a System.Data.DataRowView or some other container.  
                ' If DataTextField is set, use it to determine which  
                ' field to render. Otherwise, use the first field.                     
                If DataTextField.Length > 0 Then
                    box.Text = DataBinder.GetPropertyValue( _
                    dataItem, DataTextField, Nothing)
                    Dim props As PropertyDescriptorCollection = _

                    ' Set the "default" value of the TextBox.
                    box.Text = String.Empty

                    ' Set the true data-bound value of the TextBox, 
                    ' if possible. 
                    If props.Count >= 1 Then 
                        If props(0).GetValue(dataItem) IsNot Nothing Then
                            box.Text = props(0).GetValue(dataItem).ToString()
                        End If 
                    End If 
                End If

            Next dataItem
        End If 

    End Sub 'PerformDataBinding

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft