Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple DropDown Boxes - Best Practice 1

Status
Not open for further replies.

nevets2001uk

IS-IT--Management
Joined
Jun 26, 2002
Messages
609
Location
GB
I'm currently working on a new application and it has brought up a question of the best method for dealing with a page of many dropdowns, each of affecting the items in another. I'll try to explain the situation a bit.

I have a page with 4 dropdown lists which are all at populated from an SQL database. The user first selects a name from a list populated on page load. Another drop down allows the user to select a device type (i.e. computer, printer, scanner). When either of these are changed the Devices dropdown updates from the DB with a list of all the devices of the chosen type for the chosen user. Choosing a different Device Type also updates the items in a category dropdown.

Hope that makes some sense!

What I'd like to know is, is there a best practice for coding this style of page. At the moment it works but I'm not sure the code is that optimised. For example choosing a new user causes the app to have to look the username up in the database just to get their userID. I don’t really want to do this as it has already looked to that table in the db when populating the list in the first place. But how can I know what userID goes with the user in the list? The app then looks that up in the DeviceLine table to find all devices for that user pulling out their DeviceID's. Then it looks to the DeviceTable to get the actual device information based on the DeviceID.

This is a lot of calls to the database. The main problem I have with this method is populating the users from the database and then looking back to it to pull out the userID. Is there a way to associate the id with each entry in the dropdownbox without displaying it? I've considered populating arrays for all the data on page load but is this a good idea as much of the data won't be needed and therefore I'm wasting time pulling it all from the database in advance.

I know this is probably unclear as it's a fairly open-ended and complex question. All ideas welcomed.

Cheers,

Steve G (MCP)
 
You need to set the DataValueField and the DataTextField for the DropDownList. You can then refer to the DataValueField when filling the other boxes. I would setup the code so that the filling of the dependant boxes only happens when all the parent drop down lists have something selected. (Check to see if both the User and Device have been selected.)

Code:
										<asp:DropDownList id="cboType" runat="server" Width="192px" Font-Size="10px" Font-Names="Arial"
											Font-Bold="True" DataValueField="Type_ID" DataTextField="Type_VC"></asp:DropDownList></TD>

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
That's great. Just what I was looking for.

Thanks Jennifer.

Steve G (MCP)
 
Check out the List Link control at This does all the data relationships on the client, reducing the number of database hits and post backs.

It's very simple to use and works with most selection controls.
1. add queried tables to your dataset
2. configure relationships within the dataset
3. relate form objects to dataset objects.

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top