HyperLinkDataBindingHandler.DataBindControl(IDesignerHost, Control) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
為指定控制項解析設計階段的資料繫結。
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。
範例
下列程式碼範例會建立名為 的 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
備註
這個方法會判斷控制項的 HyperLink 和 NavigateUrl 屬性是否 Text 為數據系結。 Text如果屬性是資料系結,這個方法會將 屬性的值設定為 「DataBound」。 NavigateUrl如果屬性是資料系結,這個方法會將 屬性的值設定為文字字串,讓控制項具有運作中超連結的外觀。