DataBoundControl.PerformDataBinding(IEnumerable) Methode

Definition

Bindet beim Überschreiben in einer abgeleiteten Klasse Daten aus der Datenquelle an das Steuerelement.When overridden in a derived class, binds data from the data source to the control.

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)

Parameter

data
IEnumerable

Die IEnumerable-Datenliste, die bei einem Aufruf der PerformSelect()-Methode zurückgegeben wurde.The IEnumerable list of data returned from a PerformSelect() method call.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die PerformDataBinding -Methode in einer von DataBoundControlabgeleiteten Klasse implementiert wird.The following code example demonstrates how to implement the PerformDataBinding method in a class derived from DataBoundControl. Das TextBoxSet -Steuerelement TextBox erstellt ein Steuerelement für jedes Datenelement, an das es gebunden ist.The TextBoxSet control creates a TextBox control for each data item it is bound to. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die DataBoundControl -Klasse bereitgestellt wird.This code example is part of a larger example provided for the DataBoundControl class.

protected override void PerformDataBinding(IEnumerable retrievedData) {
    base.PerformDataBinding(retrievedData);

    // If the data is retrieved from an IDataSource as an 
    // IEnumerable collection, attempt to bind its values to a 
    // set of TextBox controls.
    if (retrievedData != null) {

        foreach (object dataItem in retrievedData) {
            
            TextBox box = 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) {
                box.Text = DataBinder.GetPropertyValue(dataItem, 
                    DataTextField, null);
            }
            else {
                PropertyDescriptorCollection props = 
                    TypeDescriptor.GetProperties(dataItem);

                // 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) {                        
                    if (null != props[0].GetValue(dataItem)) {
                        box.Text = props[0].GetValue(dataItem).ToString();
                    }
                }
            }                                        
            
            BoxSet.Add(box);
        }
    }
}
Protected Overrides Sub PerformDataBinding(ByVal retrievedData As IEnumerable)
    MyBase.PerformDataBinding(retrievedData)

    ' 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)
            Else
                Dim props As PropertyDescriptorCollection = _
                    TypeDescriptor.GetProperties(dataItem)

                ' 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

            BoxSet.Add(box)
        Next dataItem
    End If

End Sub

Hinweise

Implementieren Sie diese Methode anstelle der DataBind -Methode, wenn Sie ein Daten gebundenes Steuerelement DataBoundControl von der-Klasse ableiten.Implement this method instead of the DataBind method when you derive a data-bound control from the DataBoundControl class. Wenn Sie die Daten Bindungs Logik Ihres Steuer Elements PerformDataBinding in platzieren, können Sie DataBinding verhindern DataBound , dass das-Ereignis und das-Ereignis in der falschen Reihenfolge ausgelöst werden.Placing your control's data-binding logic in PerformDataBinding enables you to avoid the DataBinding and DataBound events being raised in the wrong order.

Obwohl die- DataBoundControl Basisklasse keine spezifische Implementierung für diese Methode bereitstellt PerformDataBinding , wird die-Methode PerformSelect von der-Methode aufgerufen, um die Werte aller Benutzeroberflächen Steuerelemente PerformSelect an die Daten zu binden, die vom anzuwenden.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.

Gilt für: