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.
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.DataBind()
End If
Dim MyConnection1 As New SqlConnection(ConnectionString)
MyConnection1.Open()
Dim Myreader1 As SqlDataReader
Dim MyCommand1 As New SqlCommand
MyCommand1.CommandText = "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.Connection = MyConnection1
Myreader1 = MyCommand1.ExecuteReader
Dim StudentList As New StudentList
Dim Course As New Course
While Myreader1.Read
If Myreader1.HasRows And StudentList.StudentName = ddlStudentID.SelectedValue Then
Me.ListBox2.Items.Add(New ListItem(Course.CourseName))
End If
End While
'Release MyReader1
Myreader1.Close()
Myreader1 = Nothing
MyConnection1.Close()
MyConnection1.Dispose()
MyConnection1 = Nothing
MyCommand1.Dispose()
MyCommand1 = Nothing
The StudentList and the Course are two tables that I created in my database.
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.