我有两次下拉。 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
但它只填充第一个选定的制造商,并且在
之后不会改变Private Sub selCurrentManuf_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles selCurrentManuf.SelectedIndexChanged
PopulateCurrentModel()
End Sub
答案 0 :(得分:0)
将selCurrentManuf.Text
更改为selCurrentManuf.SelectedItem.Value
请注意:您有一个SQL注入安全漏洞。请搜索SQL注入并修复。
答案 1 :(得分:0)
这就是所需要的! autopostback =“true”!!