Click here to Skip to main content
15,799,257 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if one category select then display subcategory in dropdown.when select other category then display othe dropdown of how can i do it????
Sergey Alexandrovich Kryukov 4-Jun-12 0:23am    
What's the problem?


you must have 2 table in your database 1st table(Category_master) where you store category with his uniq id(PK),and category name.
and in second Table Category_Detail where store all sub category with CategoryId(FK).

on dropdown selected index changed event according to either selected item or value you can fill Sub category.

you need to bind subcategory dropdown at the time of categorydrop down selected index changed.
Share this answer
Member 9027483 4-Jun-12 0:30am    
not understand...plz explain in breif....

I think you are having mulitiple dropdowns and you want filteration on the changing of one dropdown for another dropdown. If it is like that, you can use selectedindexchange event of dropdown.

On the selected index change of the first dropdown, pass the value of the first dropdown to the your load method, and fill the result to the next drop down.

Happy Coding :)
Share this answer
try like this

under page load event load the dropdown1 then bind dropdown2 under dropdownlist1 selected index changed event
cmd = New SqlCommand("select * from sample", con)
        dr = cmd.ExecuteReader()

 DropDownList1.DataSource = dr
        DropDownList1.DataTextField = "name"
        DropDownList1.DataValueField = "name"


under dropdownlist1 selected index changed event
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        cmd = New SqlCommand("select * from sample1 where name='" + DropDownList1.SelectedItem.ToString() + "' ", con)
        dr = cmd.ExecuteReader()
        DropDownList2.DataSource = dr
        DropDownList2.DataTextField = "name"
        DropDownList2.DataValueField = "name"


  End Sub
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900