Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

13 Experts available now in Live!

Get 1:1 Help Now