How do I fill a List Box from a drop down list selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Boheim
    New Member
    • Nov 2007
    • 3

    How do I fill a List Box from a drop down list selection

    I have two controls on my page:
    1) A list box
    2)A drop down list

    I want my users to be able to select from the drop down list and the related data be shown in the list box.
    For example: lets say the data in the combo box were the names of various students. I want the users to select a student name and then their classes be listed in the list box.

    I am using a database. please help. It is greatly appreciated.
  • Mohan Krishna
    New Member
    • Oct 2007
    • 115

    #2
    Originally posted by Boheim
    I have two controls on my page:
    1) A list box
    2)A drop down list

    I want my users to be able to select from the drop down list and the related data be shown in the list box.
    For example: lets say the data in the combo box were the names of various students. I want the users to select a student name and then their classes be listed in the list box.
    Hi

    Please be clear that if you want to show the class of a particular student, selected from dropdown, why you should go for a listbox!

    Anyhow, search the database based on the selected student name and then list.additem(ro llno & class...) [ the rollno, class, etc. are fields in the database]

    Hope you would be clear and ALL THE BEST!
    Last edited by Killer42; Nov 20 '07, 11:32 PM.

    Comment

    • Boheim
      New Member
      • Nov 2007
      • 3

      #3
      Ok. This is my code so far.

      [CODE=vb]'Fill the List box with the appropriate class for the selected student'
      If IsPostBack Then
      ListBox2.DataBi nd()
      End If
      Dim MyConnection1 As New SqlConnection(C onnectionString )
      MyConnection1.O pen()

      Dim Myreader1 As SqlDataReader
      Dim MyCommand1 As New SqlCommand

      MyCommand1.Comm andText = "SELECT [Student List].[Student ID], [Student List].[Student Name], Course.[Course Name] FROM Course INNER JOIN [Class List] ON Course.[Course ID] = [Class List].[Course ID] INNER JOIN [Student List] ON [Class List].[Course ID] + [Class List].[Section ID] + [Class List].[Semester ID] + [Class List].[Class Year] = [Student List].[Student Class]"

      MyCommand1.Conn ection = MyConnection1
      Myreader1 = MyCommand1.Exec uteReader

      Dim StudentList As New StudentList
      Dim Course As New Course

      While Myreader1.Read

      If Myreader1.HasRo ws And StudentList.Stu dentName = ddlStudentID.Se lectedValue Then
      Me.ListBox2.Ite ms.Add(New ListItem(Course .CourseName))
      End If
      End While

      'Release MyReader1
      Myreader1.Close ()
      Myreader1 = Nothing
      MyConnection1.C lose()
      MyConnection1.D ispose()
      MyConnection1 = Nothing
      MyCommand1.Disp ose()
      MyCommand1 = Nothing[/CODE]

      When I execute this code there is nothing shown in Listbox2. I only want the specific classes for the selected student shown in listbox2. Please help and thanks in advance.
      Last edited by Killer42; Nov 20 '07, 11:34 PM. Reason: Added CODE=vb tag

      Comment

      Working...