有2個DropDownLists在我的網頁 1.ddlVehicleBrand 2.ddlVehicleModel如何將項目添加到一個DropDownList無需重新加載頁面
我加入汽車品牌的ddlVehicleBrand在Page_Load事件數據庫。沒有問題。 但是,如果我在ddlVehicleBrand列表中選擇豐田,所有豐田車型都應該加載到ddlVehicleModel列表中,而無需重新加載整個頁面。
我使用了ddlVehicleBrand的SelectedIndexChanged事件。但是,當我改變了選定的索引,整個頁面刷新和ddlVehicleBrand選定的索引將是第一個值。
我的代碼如下
<body>
<form id="form1" runat="server" >
<div>
<asp:DropDownList ID="ddlVehicleBrand" runat="server" onselectedindexchanged="ddlVehicleBrand_SelectedIndexChanged" AutoPostBack="true"/>
<br />
<br />
<asp:DropDownList ID="ddlVehicleModel" runat="server" />
<br />
<br />
<br />
</div>
</form>
當我改變第一個DropDownList的選擇的索引,Page_Load事件被自動調用。 如何在不刷新整個頁面的情況下爲每個品牌加載特定型號。 在此先感謝
這是一個衆所周知的情況,稱爲「級聯下拉菜單」。 [This](https://www.google.ie/search?client=ubuntu&channel=fs&q=asp.net+cascading+dropdown&ie=utf-8&oe=utf-8&gws_rd=cr&ei=hx4NVuW2DIP3aL2botgM)應該讓你開始使用 – Andrei
'asp:updatepanel' – fubo
你將不得不使用ajax來實現這一點。有很多例子說明如何做到這一點,例如[stackoverflow.com/questions/5216990/populating-a-drop-down-list-using-ajax](http://stackoverflow.com/questions/5216990/populating-a-drop-down-list-using-ajax) – markpsmith