Click here to Skip to main content
15,909,835 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 subcategory...so how can i do it????
Posted
Comments
Sergey Alexandrovich Kryukov 4-Jun-12 0:23am    
What's the problem?
--SA

Hi,

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
 
Comments
Member 9027483 4-Jun-12 0:30am    
not understand...plz explain in breif....
Hi,

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
EX:
SQL
cmd = New SqlCommand("select * from sample", con)
        dr = cmd.ExecuteReader()

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

        DropDownList1.DataBind()
        dr.Close()
        con.Close()


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

        DropDownList2.DataBind()
        dr.Close()
        con.Close()

  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