如何在另一个选择中进行选择选项更改选项

时间:2011-10-03 08:46:18

标签: javascript asp.net ajax vb.net

我有两次下拉。 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

2 个答案:

答案 0 :(得分:0)

selCurrentManuf.Text更改为selCurrentManuf.SelectedItem.Value

请注意:您有一个SQL注入安全漏洞。请搜索SQL注入并修复。

答案 1 :(得分:0)

这就是所需要的! autopostback =“true”!!