Well that works on DropDownList1 (countries) *but* DropDownList2 (states)
no longer works
DropDownList2 pulls its data based on what is selected in DropDownList1 .
What do you think?
DropDownList1.Items.Clear()
DropDownList1.DataSource = SqlDataSource1
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "All")
DropDownList2.Items.Clear()
DropDownList2.DataSource = SqlDataSource2
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, "All")
Well obviously not!
If the Items collection of the second DropDownList is dependent on the
selected item of the first, then you have three choices:
1) In Page_Init, query all the possible options for DropDownList2 and pump
them into a client-side JavaScript array. Then, when the selectedIndex of
DropDownList1 changes, repopulate DropDownList2 appropriately through
client-side JavaScript. Bigger hit when the page is loaded initially, but
avoids subsequent postbacks...
2) Wire up an OnSelectionChanged server-side event for DropDownList1, set
its AutoPostBack property to true, and requery the contents of DropDownList2
server-side. Much smaller initial hit, but will need a postback every time
the selectedIndex of DropDownList changes.
3) Use Ajax. Sort of a combination of the first two options...