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
3 2325 Frinavale 9,735
Recognized Expert Moderator Expert
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 CascadingDropDo wn control that comes with the Ajax Toolkit.
If you download the Ajax Toolkit you will see an example of what they did.
-Frinny
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.
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".
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 a user selects
a country I could automatically populate the state drop down menu
Any help is appreciated
-- bg mahesh
|
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 work-arounds do you use in this
case? maybe DHTML?
do you have any example ?
Javascript allows you to create the options of the drop-down list
dynamically but not the drop-down list itself, I believe.
Actually the same question goes for any other HTML...
|
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 aspx page. But the problem is
these tend to really slow the development -- it takes up to 15 seconds for
the page to come up in VS.NET design environment, so I'm thinking about
taking these out and populating the controls dynamically using the...
|
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 select any skill in 1st drop down list then i'll select % of this
skill in the 2nd list box , based on the percentage i've selected in the 2nd
list box it has to display
2 sets of drop down list boxes at run time one for selecting skill and
|
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 value of the corresponding
field. I am doing something like this:
ddlexample.DataSource = mydatareader
ddlexample.DataValueField = "ID"
| |
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 and the next time I go to
drop down the list, all the customer numbers are doubled
(1015,1016,1017,1015,1016,1017..)
How do I get that to stop? Do I have to check if it's a post back or
something like that?
I'm fairly new at this, if you...
|
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 use the
System.DirectoryServices.ActiveDirectory namespace. I don't even know if
this is the right way to go as I can't seem to find anything in that
namespace that would help me query active directory for names.
I can't use an LDAP query...
|
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 a HTML file
into the content area of the same page.
I know it is recommended to put everything into database, but we want
the web site to be very "portable", so the drop-downlist and the
content should both in text files.
Let's say the...
|
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 Array("-----");
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |