2011-10-03 169 views
1

我有兩個下拉菜單。 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 
+0

這個問題與.net,ajax,vb.net,vb,asp等沒有任何關係,只關注javascript。 –

+0

是[這個例子](http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/)你打算做什麼?或[this one](http://weblogs.asp.net/raduenuca/archive/2011/03/06/asp-net-mvc-cascading-dropdown-lists-tutorial-part-1-defining-the-problem-而最context.aspx)? – JMax

+0

啊是的,這就是我想要做的,但xample是在C#我認爲我是usin vb – Beginner

回答

0

這就是所有需要的! autopostback =「true」!

+0

哇真的..... – CheckRaise

0

變化selCurrentManuf.TextselCurrentManuf.SelectedItem.Value

請注意:你有一個SQL注入安全漏洞。請搜索SQL注入並修復。

+0

你現有的代碼有'selCurrentManuf',沒有更多的代碼我不能說你爲什麼會得到這個錯誤。錯字?你換了別的東西嗎? – Hogan

+0

對不起,我在另一頁上試了一下。但即使在我顯示的頁面上,當用戶放下盒子並更改模型時,其他下拉的值也不會改變,它不會再次運行該功能 – Beginner

+0

您是否已掛鉤on on change事件? on change事件應該調用上面的代碼。 – Hogan

相關問題