Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
When something is selected in a DropDownList, I want this to change what is displayed in a ListBox.

I would like to make something the same as this:
Example
Please see the "Filter" DropDownList which changes the data in the ListBox below it.

What is the easiest way to do this using ASP.NET and VB?
is there any tutorial regarding this?
I created a code but so far no good.
It only shows the first default text of the dropdown and when you choose another text the list box when blank
VB
Dim strSQL As String
Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT [CourseTitle] FROM [tblTrainingPlan] WHERE ([Category] LIKE '%' + @Category + '%')"
connection.Open()

Dim command As New SqlCommand(strSQL, connection)
command.Parameters.AddWithValue("@Category", ddcategory.SelectedValue)
cbTitle.DataSource = command.ExecuteReader
cbTitle.DataTextField = "CourseTitle"
cbTitle.DataValueField = "CourseTitle"
cbTitle.DataBind()
command.Dispose()
connection.Close()
Posted
Updated 16-May-11 14:55pm
v2
Comments
walterhevedeich 16-May-11 20:49pm    
what do you mean so far no good? are there any errors? or does it behave correctly? elaborate your scenario.
janwel 16-May-11 20:53pm    
Sir it only post the first text on the dropdownlist and when I hit second text of the dropdown, the data of the list box went all blank(white)
saxenaabhi6 16-May-11 21:31pm    
show the code of onclick event of your dropdown
janwel 16-May-11 21:38pm    
sir i only add text from smart tags which is the same as the category in database
janwel 16-May-11 21:56pm    
sir the the error

if on server side:

1. load the dropdown on page load inside the if condition of 'not postback' (we discussed it before in your previous questions)
2. load and bind the listbox on the click event of dropdown

if on client side (i.e in javascript)
read this
 
Share this answer
 
v2
Comments
janwel 16-May-11 21:55pm    
sir found the error ^^ thanks anyway
XML
<asp:DropDownList ID="ddcategory" runat="server" Height="27px" Width="293px" AutoPostBack="True">
    <asp:ListItem Value="4">Fluor University Functional Courses (instructor-led)</asp:ListItem>
    <asp:ListItem Value="1">GEE 51 Bulletin Requirements</asp:ListItem>
    <asp:ListItem Value="2">Cross Functional Courses</asp:ListItem>
    <asp:ListItem Value="3">Functional Courses (online)</asp:ListItem>
    <asp:ListItem Value="5">Local Functional Courses (instructor-led)</asp:ListItem>
    <asp:ListItem Value="6">External Courses</asp:ListItem>
    <asp:ListItem Value="7">Other Courses</asp:ListItem>
    <asp:ListItem></asp:ListItem>
</asp:DropDownList></div>

Sir this is my code on dropdownlist . there is no click event
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900