Results 1 to 6 of 6

Thread: DropDownList.SelectedIndexChanged

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    21

    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

  2. #2
    Member Nikhil Aggarwal's Avatar
    Join Date
    Jun 2005
    Location
    New Delhi, India
    Posts
    36

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    21

    Re: DropDownList.SelectedIndexChanged

    Thank u very much

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    21

    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.

  5. #5
    Member Nikhil Aggarwal's Avatar
    Join Date
    Jun 2005
    Location
    New Delhi, India
    Posts
    36

    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:
    1. If Not IsPostBack Then
    2.             'Code to add items to list 1
    3.             DropDownList1.Items.Add("1")
    4.             DropDownList1.Items.Add("2")
    5.             DropDownList1.Items.Add("3")
    6. End If

    ~Nikhil

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    21

    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
  •  



Click Here to Expand Forum to Full Width