Comparteix a través de


ListControlDataBindingHandler.DataBindControl(IDesignerHost, Control) Método

Definición

Realiza un enlace de datos sobre el control especificado.

public:
 override void DataBindControl(System::ComponentModel::Design::IDesignerHost ^ designerHost, System::Web::UI::Control ^ control);
public override void DataBindControl (System.ComponentModel.Design.IDesignerHost designerHost, System.Web.UI.Control control);
override this.DataBindControl : System.ComponentModel.Design.IDesignerHost * System.Web.UI.Control -> unit
Public Overrides Sub DataBindControl (designerHost As IDesignerHost, control As Control)

Parámetros

designerHost
IDesignerHost

IDesignerHost para el documento que contiene el control.

control
Control

Clase Control que se va a enlazar.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el DataBindControl método para agregar un mensaje de cadena al control asociado SimpleRadioButtonList cuando ese control está enlazado a datos.

Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase ListControlDataBindingHandler.

// Override the DataBindControl. 
public override void DataBindControl(IDesignerHost designerHost, 
    Control control)
{
    // Create a reference, named dataSourceBinding, 
    // to the control DataSource binding.
    DataBinding dataSourceBinding = 
        ((IDataBindingsAccessor)control).DataBindings["DataSource"];

    // If the binding exists, create a reference to the
    // list control, clear its ListItemCollection, and then add
    // an item to the collection.
    if (! (dataSourceBinding == null))
    {
        SimpleRadioButtonList simpleControl = 
            (SimpleRadioButtonList)control;

        simpleControl.Items.Clear();
        simpleControl.Items.Add("Data-bound Radio Button.");
    }
} // DataBindControl
' Override the DataBindControl.
Public Overrides Sub DataBindControl( _
ByVal designerHost As IDesignerHost, _
ByVal control As Control)

    ' Create a reference, named dataSourceBinding,
    ' to the control's DataSource binding.
    Dim dataSourceBinding As DataBinding _
        = CType( _
        control, _
        IDataBindingsAccessor).DataBindings("DataSource")

    ' If the binding exists, create a reference to the
    ' list control, clear its ListItemCollection, and then add
    ' an item to the collection.
    If Not (dataSourceBinding Is Nothing) Then
        Dim simpleControl As SimpleRadioButtonList = _
            CType(control, SimpleRadioButtonList)

        simpleControl.Items.Clear()
        simpleControl.Items.Add("Data-bound Radio Button.")
    End If
End Sub

Comentarios

Si el ListControl control especificado por control tiene un origen de datos especificado dentro de su DataBindings propiedad, el DataBindControl método borra la Items colección de ListControly, a continuación, agrega un mensaje de cadena que indica que ListControl está enlazado a la Items colección.

Se aplica a

Consulte también