我有两个下拉菜单。 SelCurrentManuf 和 selCurrentModel。我希望 selCurrentModel 中的选项根据 selCurrentManuf 中选择的选项进行更改。我该怎么做?
<asp:DropDownList runat="server" ID="selCurrentManuf"></asp:DropDownList>
<asp:DropDownList runat="server" ID="selCurrentModel"></asp:DropDownList>
这就是我目前填充 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
但它只填充第一个选定的manuf,并且之后不会改变
Private Sub selCurrentManuf_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles selCurrentManuf.SelectedIndexChanged
PopulateCurrentModel()
End Sub
最佳答案
将selCurrentManuf.Text
更改为selCurrentManuf.SelectedItem.Value
请注意:您存在 SQL 注入(inject)安全漏洞。请搜索 SQL 注入(inject)并修复。
关于javascript - 如何使一个选择选项更改另一个选择中的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7632810/