共用方式為


ListControlDataBindingHandler.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

範例

下列程式代碼範例示範如何覆寫 方法, DataBindControl 以在該控件系結數據時,將字串訊息新增至相關聯的 SimpleRadioButtonList 控件。

此程式代碼範例是提供給 類別之較大範例的 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

備註

ListControl如果 所control指定的控件在其 屬性內DataBindings指定了數據源,則方法會Items清除的ListControl集合,DataBindControl然後加入字串訊息,ListControl指出 系結至Items集合的數據。

適用於

另請參閱