HyperLinkDataBindingHandler.DataBindControl(IDesignerHost, Control) Méthode

Définition

Résout la liaison de données créée au moment du design pour 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 aux données.

Exemples

L’exemple de code suivant crée une classe nommée CustomHyperLinkDataBindingHandler, qui dérive de la HyperLinkDataBindingHandler classe. Il résout la liaison de données au moment du design pour la ImageUrl propriété de la CustomHyperLink classe afin que le texte de l’espace réservé soit affiché pour la propriété lorsqu’elle est liée aux données au moment du design.

// Derive a class from the HyperLinkDataBindingHandler. It will 
// resolve  data binding for the CustomHyperlink at design time.
public class CustomHyperLinkDataBindingHandler : 
    HyperLinkDataBindingHandler
{
    // Override the DataBindControl to set property values in  
    // the DataBindingCollection at design time.
    public override void DataBindControl(IDesignerHost designerHost, 
        Control control)
    {
        DataBindingCollection bindings = 
            ((IDataBindingsAccessor)control).DataBindings;
        DataBinding imageBinding = bindings["ImageUrl"];

           // If Text is empty, supply a default value.
        if (!(imageBinding == null))
        {
            CustomHyperLink hype = (CustomHyperLink)control;
            hype.ImageUrl = "Image URL.";
        }

        // Call the base method to bind the control.
        base.DataBindControl(designerHost, control);
    } // DataBindControl
} // CustomHyperLinkDataBindingHandler
' Derive a class from the HyperLinkDataBindingHandler. It will 
' resolve  data binding for the CustomHyperlink at design time.
Public Class CustomHyperLinkDataBindingHandler
    Inherits HyperLinkDataBindingHandler

    ' Override the DataBindControl to set property values in  
    ' the DataBindingCollection at design time.
    Public Overrides Sub DataBindControl( _
        ByVal designerHost As IDesignerHost, ByVal control As Control)

        Dim bindings As DataBindingCollection = _
            CType(control, IDataBindingsAccessor).DataBindings
        Dim imageBinding As DataBinding = bindings("ImageUrl")

        If Not (imageBinding Is Nothing) Then
            Dim hLink As CustomHyperLink = CType(control, CustomHyperLink)
            hLink.ImageUrl = "Image URL."
        End If

        MyBase.DataBindControl(designerHost, control)
    End Sub
End Class

Remarques

Cette méthode détermine si les propriétés et NavigateUrl les Text propriétés du HyperLink contrôle sont liées aux données. Si la Text propriété est liée aux données, cette méthode définit la valeur de la propriété sur « DataBound ». Si la NavigateUrl propriété est liée aux données, cette méthode définit la valeur de la propriété sur une chaîne de texte afin que le contrôle ait l’apparence d’un lien hypertexte fonctionnel.

S’applique à