Infragistics WebCombo Data Binding

本文分享了使用 Infragistics ASP.NET WebControls 的经验,重点介绍了如何将 WebComboBox 绑定到数据源,包括如何配置数据字段、设置可见列等步骤,并通过实例演示了如何将 WebComboBox 绑定到 DataTable、ArrayList 或 ObjectCollection。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Infragistics ASP.NET web controls are very usful and populate by web page developers. In this series articles I will share my expierences on Infragistics controls usage with you. The topic of this blog is how to bind WebCombo to a data source.

You can bind WebCombo to an ArrayList, Object Collection or DataTable, and it supports binding to single column and multiple columns. Now let's look an example.

1. Bind To a DataTable With Single Column Visible

The ASP.NET page looks like below:

WebCombo-DataBinding-example.jpg

All the WebCombo controls bind to a DataTable which load data from the database. The DataTable has 2 fields - one for DisplayValue and the other for DataValue of the WebCombo control. Follow mw as the following steps.

WebCombo-DataBinding-Columns-Add.jpg

WebCombo-DataBinding-DataTextField.jpg

Select the WebCombo control, in the Properties window, click "..." button on the "Column" property to open the "Column Collection Editor" window, as shown above.

Remove the default column 0 first, because clolumn name did not update while you assign "Key" and "BaseColumnName" to it.

Now click "Add" button to add new columns. Follow the steps from 1 to 4 shown as above figure.

BaseColumnName - the name of the column in the data store

Key - A unique string identifier for this column within the Columns collection.

Hiden - Determines whether a column is hidden from view. Default is False.

In this example we need the "Code" column to be visible and "ID" column invisible, so I set Hidden = False for "Code" column and Hidden = True for "ID" column.

After "Code" and "ID" columns added, click "OK" button. Now you can see a dropdownlist containing "Code" and "ID" when you click "DataTextField" and "DataValueField" property of the WebCombo control in the Properties window. Select "Code" for DataTextField property and "ID" for DataValueField property.

DataTextField - Specifies the column name from the dropdown that will be used to display the text content of the top portion of the WebCombo.

DataValueField - Specifies the column name from the dropdown that will be used as the source for the DataValue of the WebCombo control.

Next we need to set other properties of the WebCombo control, as shown below.

WebCombo-DataBinding-DropdownLayout-1.jpg

So far the only thing to do is write few lines of code to bind to data source, as below.

Public Shared Sub BindWebCombo(ByRef control As WebCombo, ByRef dataSource As DataTable)
With control
' data bingding
.DataSource = dataSource
.DataBind()
End With
End Sub

2. Bind To a DataTable With MultilpeColumns Visible

Bind to multiple columns is very similar with the steps above. Let's see what the difference is.

a. Set "ColHeadersVisible" property to be "Yes".

WebCombo-DataBinding-DropdownLayout-2.jpg

b. Set value for Caption property of Column Header.

WebCombo-DataBinding-Columns-Show-Header.jpg

c. set Hidden property to be "False" (see figure above)

The page now look like below.

WebCombo-DataBinding-Multi-Columns.jpg

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13651903/viewspace-1037417/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13651903/viewspace-1037417/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值