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 MyEts() Dim oConn As SqlConnection Dim oCMD As SqlCommand Dim oDR As SqlDataReader Dim oLI As System.Web.UI.WebControls.ListItem ddl_Et.Items.Clear() oConn = New SqlConnection(ConfigUtility.CONNN) oCMD = New SqlCommand("Execute ReturnEts") 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_Et.Items.Add(oLI) End While Else 'nothing End If oDR.Close() oConn.Close() End Sub 'ASP part <aspropDownList ID="ddl_Et" 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 RetOptions '" & EID & "'") 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("sOption")).Trim oLI.Text = CStr(oDR("sOption")).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>
You need to use the OnChange event handler on the first dropdown. I haven't done regular ASP in years, but here is a link that describes one method to do what you want. http://www.plus2net.com/asp-tutorial/db-dropdown.php
If there aren't many values in the 2nd combo box you can write all the combo boxes to the HTML page with display= none . When a user will select a value in the first combo box it will trigger the onChange event which will display the needed combo-box. (Make sure that your page size stays small -If not you need to use other solution) I strongly recommend to save the query result in the Application object - you relay don't want to access the database each time a user browse your site.