By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,501 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,501 IT Pros & Developers. It's quick & easy.

How to add items in DropDownListbox if I select another DropDownListbox

P: 1
Dear Friends

This is Jeyapriya. Right now I am working in the ASP.NET with VB coding & the back end is SQL SERVER 2000.

My dilemma is

I have to design a form with 2 DropDownListboxes. I have to load the ‘names of the theater’ on the 1st DropDownListbox & the names of the movie on the second DropDownListbox. That’s why I have created 2 tables named ‘theater’ and ‘movie’ on sql server 2000. The ‘theater’ table consists of 2 fields
1) tid
2) tname

The movie table has 2 fields

1) mid
2) mname

If I select a item in theater DropDownListbox, then the corresponding movies should be filled on the movie DropDownListbox. And by default, both the DropDownListboxes should show ‘CHOOSE’(‘Choose Theater’ in Theater-DropDownListbox and ‘Choose Movie’ in Movie DropDownListbox)

Now the problem is, I don’t know what is the next step to do.
Mar 19 '08 #1
Share this Question
Share on Google+
1 Reply


balabaster
Expert 100+
P: 797
Dear Friends

This is Jeyapriya. Right now I am working in the ASP.NET with VB coding & the back end is SQL SERVER 2000.

My dilemma is

I have to design a form with 2 DropDownListboxes. I have to load the ‘names of the theater’ on the 1st DropDownListbox & the names of the movie on the second DropDownListbox. That’s why I have created 2 tables named ‘theater’ and ‘movie’ on sql server 2000. The ‘theater’ table consists of 2 fields
1) tid
2) tname

The movie table has 2 fields

1) mid
2) mname

If I select a item in theater DropDownListbox, then the corresponding movies should be filled on the movie DropDownListbox. And by default, both the DropDownListboxes should show ‘CHOOSE’(‘Choose Theater’ in Theater-DropDownListbox and ‘Choose Movie’ in Movie DropDownListbox)

Now the problem is, I don’t know what is the next step to do.
Firstly run a query to pull a list of your theatres using an SqlCommand and an SqlDataReader. Bind the query results to the first dropdownlist using DropDownList1.DataSource = MyDataReader1

In the SelectedIndexChanged event of the first dropdownlist, trigger a database query to select the movies at that theatre. Use the same method to bind the query results to the second dropdownlist.

In the DataBound event of each of the dropdownlists, insert the "Select..." entry at the beginning of the dropdownlist using DropDownList.Insert(0, "Select..."). You can comma separate the Handles clause to use the same code, but you'll have to CType the sender to DropDownList: CType(Sender, DropDownList).Insert(0, "Select...").

It's a relatively straightforward process...you should be able to find the relevant information easily by picking keywords out of what I've written.

Lastly, I would use an AJAX extender to run the second query - this way you don't have to reload the whole page after the user selects the theatre - the second dropdown will be populated in the background.
Mar 19 '08 #2

Post your reply

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