2013-10-24 55 views
0

我有一個下拉列表,我在其中動態添加列表項。我將autopostback設置爲true,但是當我在下拉列表中選擇一個項目時似乎沒有發生。回傳不工作?

標記

`<asp:DropDownList runat="server" AutoPostBack="true" ID="restaurant_city_con" CssClass="selectboxindex"></asp:DropDownList>` 

代碼

`if (!this.IsPostBack) 
{ 
    addStates(); 
    showData(); 
    dashboardPageFunction(); 
    ordersPageFunction(); 
    reportsPageFunction(); 
    categoriesPageFunction(); 
    menuPageFunction(); 
    offersPageFunction(); 
    bookingPageFunction(); 
} 
else 
{ 
    addCities(); 
    addZipCode(); 
}` 

的背後有什麼我做錯了嗎?

+0

你需要添加一個SelectedIndexChanged事件以及 –

+0

仍不加工。 –

+0

您是否嘗試過使用selectedindexchanged事件中的斷點進行調試? –

回答

2

您需要處理OnSelectedIndexChanged事件,像這樣:

標記:

<asp:DropDownList runat="server" AutoPostBack="true" ID="restaurant_city_con" 
    CssClass="selectboxindex" 
    OnSelectedIndexChanged="restaurant_city_con_SelectedIndexChanged"> 
</asp:DropDownList> 

代碼隱藏:

protected void restaurant_city_con_SelectedIndexChanged(object sender, 
                 EventArgs e) 
{ 
    // Do something with selected item here 
    Label1.Text = "You selected " + restaurant_city_con.SelectedItem.Text + 
       " with a value of " + restaurant_city_con.SelectedItem.Value + 
       "."; 
} 
+0

編譯器錯誤消息:CS1061:'ASP.restaurantdashboard_aspx'不包含'restaurant_city_con_SelectedIndexChanged'的定義,也沒有接受'ASP.restaurantdashboard_aspx'類型的第一個參數的擴展方法'restaurant_city_con_SelectedIndexChanged' –

+0

您可以發佈所有標記和代碼 - 背後? –

+0

我解決了它。無論如何,謝謝 –