简体   繁体   中英

How to make a select option change options in another select

I have two drop down. SelCurrentManuf and selCurrentModel. I want the option in selCurrentModel to change depending on the option selected in selCurrentManuf. How do i do it?

<asp:DropDownList runat="server" ID="selCurrentManuf"></asp:DropDownList>
<asp:DropDownList runat="server" ID="selCurrentModel"></asp:DropDownList>

This is how i am currently populating selCurrentModel

Public Sub PopulateCurrentModel()
        Dim mySelectQuery As String = "SELECT * FROM Model where ManufID = "+ selCurrentManuf.Text+";"
        Dim myConnection As New MySqlConnection(Session("localConn"))
        Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)

        myConnection.Open()
        Dim myReader As MySqlDataReader
        myReader = myCommand.ExecuteReader()

        While myReader.Read
            Dim newListItem As New ListItem
            newListItem.Value = myReader.GetString("Modelid")
            newListItem.Text = myReader.GetString("desc")
            selCurrentModel.Items.Add(newListItem)
        End While

        myReader.Close()
        myConnection.Close()
    End Sub

but it only populates the first selected manuf, and doesnt change after

Private Sub selCurrentManuf_SelectedIndexChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles selCurrentManuf.SelectedIndexChanged

       PopulateCurrentModel()
End Sub

Change selCurrentManuf.Text to selCurrentManuf.SelectedItem.Value

PLEASE NOTE: You have a SQL Injection security vulnerability. Please search on SQL Injection and fix.

This was all that was needed! autopostback="true" !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM