|
-
Jun 13th, 2005, 01:41 AM
#1
Thread Starter
Junior Member
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
-
Jun 13th, 2005, 02:18 AM
#2
Member
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
-
Jun 13th, 2005, 02:21 AM
#3
Thread Starter
Junior Member
Re: DropDownList.SelectedIndexChanged
-
Jun 13th, 2005, 02:58 AM
#4
Thread Starter
Junior Member
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.
-
Jun 13th, 2005, 03:25 AM
#5
Member
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
-
Jun 13th, 2005, 03:45 AM
#6
Thread Starter
Junior Member
Re: DropDownList.SelectedIndexChanged
Dear Nikhil
it is working good now
thank u very much for ur help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|