tk3
asked on
Populating Drop-Down Control
I have a table with two columns which I would like to drive a drop-down control. I would like the DataTextField to be the values of the two columns concatenated together with some punctuation added, and the DataValueField to be the value of the second column only.
Example:
Data: Column 1: "Attendee"
Column 2: "150"
In the Drop-Down: DataTextField: "Attendee ($150)"
DateValueField: "150"
I can't seem to concatenate the columns together, either in the SQL statement itself, or by going through the data in a datareader and formatting the entries into the drop-down.
I have seen some VB samples like this:
Loop through a datareader and for each row:
droplist.Items.Add(New ListItem("textfield", "valuefield"))
but I can't get anything like this to work in C#.
Thanks for the help.
Ted
Example:
Data: Column 1: "Attendee"
Column 2: "150"
In the Drop-Down: DataTextField: "Attendee ($150)"
DateValueField: "150"
I can't seem to concatenate the columns together, either in the SQL statement itself, or by going through the data in a datareader and formatting the entries into the drop-down.
I have seen some VB samples like this:
Loop through a datareader and for each row:
droplist.Items.Add(New ListItem("textfield", "valuefield"))
but I can't get anything like this to work in C#.
Thanks for the help.
Ted
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi there,
Do you mean something like this?
// assuming that you have a list named myList containing elements type of myListItem
// and you have a drop down list named myDropDownList
foreach (myListItem li in myList)
{
myDropDownList.Items.Add(n
}
You may populate the collection to be iterated from your database query and use the dataset, or if you are using a database access layer, you may use your own types of collections.
However there is another way to populate these dropdownlists, you may directly set the datasource of the dropdownlist to a 2 column dataset that you populated.
Hope this helps,
Sincerely,
Onur
www.onura.net