Kwah009
Kwah009

Reputation:

Is it possible to bind more than one column to a DropDownList's DataTextField?

The following is my code...

DropDownList2.DataSource = td.DataSet DropDownList2.DataSource = td DropDownList2.DataTextField = td.Columns("Name").ColumnName.ToString DropDownList2.DataValueField = td.Columns("VendorCode").ColumnName.ToString DropDownList2.DataBind()

Now I have a requirement to show the type of vendor and the Name of the vendor on the dropdownlist. The type of vendor can be retreived with this statement...

td.Columns("VendorType").ColumnName.ToString

Is it possible to do this? Please help

Upvotes: 3

Views: 1892

Answers (2)

lc.
lc.

Reputation: 116528

Unfortunately it's not possible to bind more than one field to a single property.

But, it looks like you're using a DataSet and DataTable, so you can create a derived column with a single string containing both the Name and VendorType, formatted how you like. You'll want to look into the DataColumn.Expression property. Set this to automatically calculate the new column.

Upvotes: 2

TheVillageIdiot
TheVillageIdiot

Reputation: 40517

Not possible to bind DataTextField to more than one column. You can create a derived column containing Vendor Name and Vendor Type and bind it to DataTextField property.

Upvotes: 3

Related Questions