2013-10-23 40 views
0

嗨,我正在開發一個asp.net的Web應用程序,因爲我創建一個註冊表單。在註冊表格頁面上,我有三個名爲國家,州,城市的Dropdownlists。 因此,當用戶選擇任何國家時,該國的州將顯示在狀態的下拉列表中,以及用戶從州下拉列表中選擇州時,他可以在下拉列表中看到城市列表。層疊dropdownlist沒有重新加載頁面在asp.net

我已經實現了該功能,但是當用戶在下拉列表中選擇值時,會發生回發。 在我的情況下,我不想在用戶選擇國家或州時重新加載頁面,所以我試圖通過使用ajax工具包來實現相同的功能。但我無法使用ajax實現相同的功能。

所以簡而言之,我的問題是:從asp.net中的dropdownlist中選擇國家,州和城市,無需重新加載頁面。

在這裏,我給你的ASPX部分。

請幫幫我。

CountryDropDown

<asp:DropDownList ID="DropDownListCountry" runat="server" Enabled="false" 
     OnSelectedIndexChanged="DropDownListCountry_OnSelectedIndexChanged" 
     AutoPostBack ="false"> 
    <asp:ListItem>India</asp:ListItem> 
    <asp:ListItem>Other</asp:ListItem> 
</asp:DropDownList> 

StateDropDown

<asp:UpdatePanel ID="UpdatePanel1" runat="server" > 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="DropDownListCountry" EventName="OnSelectedIndexChanged" /> 
    </Triggers> 
    <ContentTemplate> 
     <asp:DropDownList runat="server" ID="DropDownListState" Enabled="false" 
      OnSelectedIndexChanged="DropDownListState_OnSelectedIndexChanged"> 
     </asp:DropDownList> 
    </ContentTemplate> 
</asp:UpdatePanel> 
+0

研究.NET Web方法。基本上是ajax調用來執行代碼隱藏功能。 [這裏是一個例子](http://stackoverflow.com/questions/14631238/pass-and-return-a-string-into-vb-net-web-method) – ElliotM

+0

你的代碼看起來不錯。你得到什麼錯誤? –

+0

我沒有收到任何錯誤,但我無法實現所需的功能。 –

回答

0

哇你設法讓解釋什麼是錯.... 但衣衫盡我所能,試圖幫助的大混亂。第一,DDL應該定義如下所示:

<asp:DropDownList ID="Contries" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Contries_SelectedIndexChanged"> 
    <asp:ListItem Text="country1" /> 
    <asp:ListItem Text="country2" /> 
</asp:DropDownList> 

第二DDL:

<asp:UpdatePanel runat="server" > 
    <ContentTemplate> 
     <asp:DropDownList ID="States" runat="server" AutoPostBack="true"> 
    <asp:ListItem Text="state1" /> 
    <asp:ListItem Text="state2" /> 


</asp:DropDownList> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="Contries" EventName="OnSelectedIndexChanged" /> 
    </Triggers> 
</asp:UpdatePanel> 

等,自動回發必須在DDL應該做的異步回傳真,

嘗試逐個刪除DDL,然後從2開始,然後向前移動。