C# - Populate a dropdown including selected index based on results of query
Posted on 2006-07-10
I have something of a dilemma. I am pulling a list of names from a database (MySQL query) and putting them into a dropdown box.
I am able to set the text and value field to the first values out of the query, but I cannot set the selected index as a specific row.
The setup is thus:
A datatable contains the information pulled from the query and is then taken by a dropdown and the values are filled like this:
DataTable DT declared earlier.
DropDownList drop = (DropDownList)e.Item.FindControl("ddListAllocations");
drop.DataSource = DT;
drop.DataValueField = "userid";
drop.DataTextField = "username";
This is called from an OnItemDataBound method in an ASP:Repeater control.
There are two tables in use here:
tblOrders contains two fields I need:
tblUsers contains two fields I need:
Is there a way to bind the orderAgent and userid together to create a selected index for each orderno?
Thanks in advance.