Поделиться через


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 , DataBindControl метод очищает Items коллекцию ListControlот , а затем добавляет строковое сообщение, указывающее, что ListControl является данными, привязанными к Items коллекции.

Применяется к

См. также раздел