469,127 Members | 1,371 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,127 developers. It's quick & easy.

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

3
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.
Nov 20 '07 #1
2 988
Mohan Krishna
115 100+
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(rollno & class...) [ the rollno, class, etc. are fields in the database]

Hope you would be clear and ALL THE BEST!
Nov 20 '07 #2
Boheim
3
Ok. This is my code so far.

Expand|Select|Wrap|Line Numbers
  1. 'Fill the List box with the appropriate class for the selected student'
  2.         If IsPostBack Then
  3.             ListBox2.DataBind()
  4.         End If
  5.         Dim MyConnection1 As New SqlConnection(ConnectionString)
  6.         MyConnection1.Open()
  7.  
  8.         Dim Myreader1 As SqlDataReader
  9.         Dim MyCommand1 As New SqlCommand
  10.  
  11.         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]"
  12.  
  13.         MyCommand1.Connection = MyConnection1
  14.         Myreader1 = MyCommand1.ExecuteReader
  15.  
  16.         Dim StudentList As New StudentList
  17.         Dim Course As New Course
  18.  
  19.         While Myreader1.Read
  20.  
  21.             If Myreader1.HasRows And StudentList.StudentName = ddlStudentID.SelectedValue Then
  22.                 Me.ListBox2.Items.Add(New ListItem(Course.CourseName))
  23.             End If
  24.         End While
  25.  
  26.         'Release MyReader1
  27.         Myreader1.Close()
  28.         Myreader1 = Nothing
  29.         MyConnection1.Close()
  30.         MyConnection1.Dispose()
  31.         MyConnection1 = Nothing
  32.         MyCommand1.Dispose()
  33.         MyCommand1 = Nothing
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.
Nov 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Richard Galli | last post: by
reply views Thread by Geary | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.