Solved

C# - Populate a dropdown including selected index based on results of query

Posted on 2006-07-10
4
396 Views
Last Modified: 2010-05-18
Hey there.

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";
drop.DataBind();

This is called from an OnItemDataBound method in an ASP:Repeater control.

There are two tables in use here:

tblOrders
tblUsers

tblOrders contains two fields I need:
orderNo
orderAgent

tblUsers contains two fields I need:
userID
userName


Is there a way to bind the orderAgent and userid together to create a selected index for each orderno?

Thanks in advance.
0
Comment
Question by:DanBAtkinson
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
harshits earned 500 total points
ID: 17072127
Hi,

I am not much sure what kind of functionality are you trying to implement. I get that you have two drop down list. What is the dependency between these two drop downs?

The syntax for selecting a particular index is DropDown.SelectedIndex= [index]; after the drop down is bound.

It will be helpful if you clarify a bit more

Harshit Sheth


0
 

Author Comment

by:DanBAtkinson
ID: 17072232
There is only one dropdown list which is bound to a repeater. Therefore, the set number of dropdown boxes is dynamic.
0
 

Author Comment

by:DanBAtkinson
ID: 17302805
Na. I was waiting for an answer.

I figured it out in the end.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question