HyperLinkDataBindingHandler.DataBindControl(IDesignerHost, Control) 方法

定义

为指定控件解析设计时数据绑定。

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)

参数

designerHost
IDesignerHost

包含该控件的文档的 IDesignerHost

control
Control

要将数据绑定到的 Control

示例

下面的代码示例创建一个名为, CustomHyperLinkDataBindingHandler派生自该类的 HyperLinkDataBindingHandler 类。 它解析类属性CustomHyperLink的设计时数据绑定ImageUrl,以便在设计时对属性显示占位符文本。

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

注解

此方法确定控件的HyperLinkNavigateUrl属性是否Text是数据绑定的。 Text如果属性是数据绑定的,此方法会将属性的值设置为“DataBound”。 NavigateUrl如果属性是数据绑定的,此方法会将属性的值设置为文本字符串,以便控件具有工作超链接的外观。

适用于