Solved

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

Posted on 2006-07-10
4
395 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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