473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Populating a Drop Down List Dynamically

147 100+
Hi

I am using C# and Access databse for a web site.

I have a drop down list which I need to populate dynamically according to results in a database.

Example

There will be 1 drop down list on the page which offers 3 makes of cars:
Mazda, Honda, Ford

The user selects this, the page performs the postback and a new box appears beside it offering 5 colours:
Red, Blue, Green White, Orange

Now let's pretend Mazda only comes in Red and blue and green.
Honda only comes Red, Green and White
For comes in Blue, White and Orange

This means if the user selects Mazda, after the page does the postback and displays drop down list 2 the only options are Red Blue and Green (etc for the other makes)

How do I populate the correct options in the drop down list depending on the choice of car. In the past, I have done this manually with if else statements, but is there any easier way?

Thanks

Dave
Nov 12 '08 #1
3 2296
Frinavale
9,735 Expert Mod 8TB
How do I populate the correct options in the drop down list depending on the choice of car. In the past, I have done this manually with if else statements, but is there any easier way?
When you need to make a logical choice, you have to use a logical control (by this I mean an If statement or select/switch case). It's not magical, it's the simple case of "IF this do that".

It sounds like you are trying to implement the example for the CascadingDropDown control that comes with the Ajax Toolkit.


If you download the Ajax Toolkit you will see an example of what they did.

-Frinny
Nov 12 '08 #2
teddarr
143 100+
These controls are awesome, and for the most part, easy to implement. The cascading dropdown is not the easiest, but there are some good examples that can be found with a simple google search.
Dec 3 '08 #3
balabaster
797 Expert 512MB
You could also get around this using a different approach than If...Then using some kind of dataset paradigm:

Dim Ford = {Color.Red, Color.White, Color.Blue}
Dim Mazda = {Color.Red, Color.Green, Color.Orange}
Dim Chevrolet = {Color.Red, Color.Green, Color.Blue}
Dim Makes = {Ford, Mazda, Chevrolet}

Make the first drop down list list items from the Makes array which lists each of the other arrays by name (otherwise it'll say {Red, White, Blue} etc). Then when you select one, it populates the second drop down list with the items in the selected array.

Of course, I'd probably go with the AJAX method previously suggested. Just thought I'd throw an alternative approach out there just for the fun of seeing if I could come up with a different solution.

You've heard the figure of speech "There's many ways to skin a cat".
Dec 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: B. G. Mahesh | last post by:
hi In the registration form I have city, state, country fields. I was wondering if there was a database available on the net which has the list of states in each of the countries. That way when...
4
by: Gurry | last post by:
Hi there I would like to write a javascript function that creates a drop-down list dynamically. I read on the docs that most HTML controls can not be created on run-time. what kind of...
1
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
5
by: TB | last post by:
Hi All: The following is probably a newbie question, but please bear with me: I am populating a drop down list with items from a database, and would the default selected item to be the current...
4
by: Pete Lux | last post by:
I have a drop down that populates on page load. The drop down brings in customer numbers from my local MSDE database. It does this fine, but I click a button that finds quotes for those customers...
2
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
1
by: chandhseke | last post by:
Hi Folks, I have designed a dynamic drop down list but having problems since it is not working as intended. Please help <html> <head> <Script language="Javascript"> var Select = new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.