attached is the code for the 2 dropdown list of which their values are retrieved from the database,how can i make the 2nd dropdown values correspond to what was selected in the first dropdown?
For example,if the 1st dropdown list is CarMakes, and the second one is CarModels,when a CarMake is selected,show appropriate CarModels.
'This is how i get values into my first dropdown list
Private Sub MyEvents()
Dim oConn As SqlConnection
Dim oCMD As SqlCommand
Dim oDR As SqlDataReader
Dim oLI As System.Web.UI.WebControls.ListItem
ddl_Event.Items.Clear()
oConn = New SqlConnection(ConfigUtility.CONNN)
oCMD = New SqlCommand("Execute ReturnEvents")
oCMD.Connection = oConn
oConn.Open()
oDR = oCMD.ExecuteReader
If oDR.HasRows Then
While oDR.Read
oLI = New System.Web.UI.WebControls.ListItem()
oLI.Value = CStr(oDR("ID")).Trim
oLI.Text = CStr(oDR("DescriptionID")).Trim
ddl_Event.Items.Add(oLI)
End While
Else
'nothing
End If
oDR.Close()
oConn.Close()
End Sub
'ASP part
<aspropDownList ID="ddl_Event" runat="server" AutoPostBack="True"></aspropDownList>
'then my second dropdown,values link by ID to the first DDL table
Private Sub EventOptions(ByVal EventID As Integer)
Dim oConn As SqlConnection
Dim oCMD As SqlCommand
Dim oDR As SqlDataReader
Dim oLI As System.Web.UI.WebControls.ListItem
ddl_EOptions.Items.Clear()
oConn = New SqlConnection(ConfigUtility.CONNN)
oCMD = New SqlCommand("Execute ReturnEventOptions '" & EventID & "'")
oCMD.Connection = oConn
oConn.Open()
oDR = oCMD.ExecuteReader
If oDR.HasRows Then
While oDR.Read
oLI = New System.Web.UI.WebControls.ListItem()
oLI.Value = CStr(oDR("sEventOption")).Trim
oLI.Text = CStr(oDR("sEventOption")).Trim
ddl_EOptions.Items.Add(oLI)
End While
Else
'nothing
End If
oDR.Close()
oConn.Close()
End Sub
<aspropDownList ID="ddl_EOptions" runat="server" AutoPostBack="True"></aspropDownList>
For example,if the 1st dropdown list is CarMakes, and the second one is CarModels,when a CarMake is selected,show appropriate CarModels.
'This is how i get values into my first dropdown list
Private Sub MyEvents()
Dim oConn As SqlConnection
Dim oCMD As SqlCommand
Dim oDR As SqlDataReader
Dim oLI As System.Web.UI.WebControls.ListItem
ddl_Event.Items.Clear()
oConn = New SqlConnection(ConfigUtility.CONNN)
oCMD = New SqlCommand("Execute ReturnEvents")
oCMD.Connection = oConn
oConn.Open()
oDR = oCMD.ExecuteReader
If oDR.HasRows Then
While oDR.Read
oLI = New System.Web.UI.WebControls.ListItem()
oLI.Value = CStr(oDR("ID")).Trim
oLI.Text = CStr(oDR("DescriptionID")).Trim
ddl_Event.Items.Add(oLI)
End While
Else
'nothing
End If
oDR.Close()
oConn.Close()
End Sub
'ASP part
<aspropDownList ID="ddl_Event" runat="server" AutoPostBack="True"></aspropDownList>
'then my second dropdown,values link by ID to the first DDL table
Private Sub EventOptions(ByVal EventID As Integer)
Dim oConn As SqlConnection
Dim oCMD As SqlCommand
Dim oDR As SqlDataReader
Dim oLI As System.Web.UI.WebControls.ListItem
ddl_EOptions.Items.Clear()
oConn = New SqlConnection(ConfigUtility.CONNN)
oCMD = New SqlCommand("Execute ReturnEventOptions '" & EventID & "'")
oCMD.Connection = oConn
oConn.Open()
oDR = oCMD.ExecuteReader
If oDR.HasRows Then
While oDR.Read
oLI = New System.Web.UI.WebControls.ListItem()
oLI.Value = CStr(oDR("sEventOption")).Trim
oLI.Text = CStr(oDR("sEventOption")).Trim
ddl_EOptions.Items.Add(oLI)
End While
Else
'nothing
End If
oDR.Close()
oConn.Close()
End Sub
<aspropDownList ID="ddl_EOptions" runat="server" AutoPostBack="True"></aspropDownList>
Last edited: