ListControlDataBindingHandler.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。
示例
下面的代码示例演示如何重写 方法, 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的数据。