forms: master/detail dropdown list?

J

Jerome

Hi,

I've got a table like this

Cat1 ¦ Item1
Cat1 ¦ Item2
Cat1 ¦ Item3
Cat2 ¦ ItemA
Cat2 ¦ ItemB

I would now like to create a master and a detail dropdownlist, meaning
the master DDL displays "Cat1; Cat2" and if I select "Cat1" for example
the detail DDl will display "Item1; Item2; Item3".

I tried different ways but nothing really works. Can anyone point me to
a working solution?

Thanks a lot!

Jerome
 
G

Grant Merwitz

by table, do you mean DataBase table or .NET dataTable

IF its a database,
you can first query the Cat items Grouping by or distinct, to give you the
list like:
Cat1
Cat2

You can then populate the first drop down with that list.
ONce the user picks on of those options, you can then do an additional
DataBase request to get the list of Items filtered by the selected category.

This will take a server postbck though and isn't the best user experience.
You can use Cacheing to speed this up, or javascript

HTH
 
J

Jerome

Hi, thanks for answering.

Yes, I meant a database table.
And populating the first DDL isn't the problem, the second is.

Since the whole list would be way to long for only one DDL, I thought it
would be better to split it in 2. So the user first chooses the category
in the first and then the item in the second. The question now was how
to populate the second DDL based on the first one.

If Postback isn't the best way, what other options do I have and how
would I implement that in my ASP.NET code?

Thanks a lot.
 
G

Grant Merwitz

The easiest most straight forward way would be to do an additional call
causing a post back.
Where for every call you'de be repopulating the same dropdowns contents with
a filetered list based on the first list.

This could be done with the SelectedIndexChanged option on the first
dropdownlist, that will call a method that reads its selected value,
retrieves a filtered list from your DB based on that value, and then binds
this list to the second DropDown.

To avoid doing a post back, you'll either have to user XmlHttp (xml over
http), to bind the list client side, or initially build javascript from your
given dataset to filter the list client side.
This is quite a bit more complex, and although a better user experience, the
first method is much easier to implement and more importantly works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top