Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net mvc return json 2 54
Word Directory is not in the drop down list 4 25
ASP.NET 5 Templates 2 65
rebind a grid after user clicks on node in treeview 1 5
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now