Partager via


ListControlDataBindingHandler.DataBindControl(IDesignerHost, Control) Méthode

Définition

Effectue une liaison de données sur le contrôle spécifié.

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)

Paramètres

designerHost
IDesignerHost

IDesignerHost pour le document qui contient le contrôle.

control
Control

Control à lier.

Exemples

L’exemple de code suivant montre comment remplacer la DataBindControl méthode pour ajouter un message de chaîne au contrôle associé SimpleRadioButtonList lorsque ce contrôle est lié aux données.

Cet exemple de code fait partie d’un exemple plus grand fourni pour la ListControlDataBindingHandler classe .

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

Remarques

Si le ListControl contrôle spécifié par control a une source de données spécifiée dans sa DataBindings propriété, la DataBindControl méthode efface la Items collection du , puis ajoute un message de ListControlchaîne indiquant que les ListControl données sont liées à la Items collection.

S’applique à

Voir aussi