Results 1 to 3 of 3

Thread: dropdownlist on select

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271

    Question dropdownlist on select

    Hi,

    I want to populate a dropdownlistwith information from my database, when a selection is made in another dropdownlist

    this is the code I want to execute:

    VB Code:
    1. Dim myConnection As New OleDBConnection(ConnectionString)
    2.     ' creates a dataset to store the information gained form the database
    3.     Dim DsMembers As Dataset = New DataSet()
    4.     Dim CommandText As String = "SELECT * from tbl_crews WHERE Name= '" & cbo_Crew.SelectedItem.Text & "'"
    5.     Dim myAdapter As OleDBDataAdapter = New OleDBDataAdapter(CommandText, myConnection)
    6.         myAdapter.Fill(DsMembers, "tbl_crews")
    7.  
    8. Dim I as integer
    9.  
    10. try
    11.  
    12.  For I = 0 To DsMembers.Tables(0).rows.count-1
    13.        Dim strtemp as String = DsMembers.tables(0).rows(I).item(0).tostring & " - " & _
    14.        DsMembers.tables(0).rows(I).item(1).tostring
    15.  
    16.        cbo_member.items.add(strtemp)
    17.  
    18.     Next I
    19.     Catch ex as Exception
    20.           lbl_Message.text = ex.ToString()
    21.     Finally
    22.  
    23.     End Try

    problem is that I don't know which command to put it under as it doesn't work on:

    VB Code:
    1. Sub cbo_Crew_SelectedIndexChanged(sender As Object, e As EventArgs)

    and suggestions?
    Thanks
    §tudz

    Studzworld.com - Portfolio

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    Putting the code in SelectedIndexChanged shouldn't be a problem.

    so firstly 2 simple questions
    1. Is autopostback set to true on the dropdown list? otherwise the event won't fire until another postback is performed.
    2. I notice there is no 'handles cbo_Crew.selectedIndexChanged' at the end of this line:
    VB Code:
    1. Sub cbo_Crew_SelectedIndexChanged(sender As Object, e As EventArgs)
    so in this case do you have
    Code:
    OnSelectedIndexChanged="cbo_Crew_SelectedIndexChanged"
    set where you declare the dropdownlist?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    the problem was I hadn't set 'postback' lol oops
    §tudz

    Studzworld.com - Portfolio

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