DropDownList.SelectedIndexChanged
I have 2 dropdown lists on one page. A selection from the first list
determines what gets listed in the second list.
but the problem nothing appears in list2.
the following code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
DropDownList1.Items.Add("a")
DropDownList1.Items.Add("b")
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
DropDownList2.Items.Clear()
Dim a As Integer
a = DropDownList1.SelectedIndex
If a = 0 Then
DropDownList2.Items.Add("selected a")
Else
DropDownList2.Items.Add("selected b")
End If
End Sub
plz help me
thanx
sara
Re: DropDownList.SelectedIndexChanged
Set the AutoPostBack property for DropDownList1 control to true.
If this property is set to false then the function DropDownList1_SelectedIndexChanged will not be called at all.
~Nikhil
Re: DropDownList.SelectedIndexChanged
Re: DropDownList.SelectedIndexChanged
Dear Nikhil
the proble was solved but still i have another problem
with every selection for list2, the items are duplicated in list 1.
Re: DropDownList.SelectedIndexChanged
Im guessing you are populating List 1 on the PageLoad event. What is happening is that items are bieng re-added to List1 every time the Page makes a round trip to the server.
Place the List1 data population code in a If block where you check if the page has been posted back or not.
VB Code:
If Not IsPostBack Then
'Code to add items to list 1
DropDownList1.Items.Add("1")
DropDownList1.Items.Add("2")
DropDownList1.Items.Add("3")
End If
~Nikhil
Re: DropDownList.SelectedIndexChanged
Dear Nikhil
it is working good now
thank u very much for ur help