簡體   English   中英

回發不起作用?

[英]Postback is not working?

我有一個下拉列表,我在其中動態添加列表項。 我將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();
}`

有什么我做錯了嗎?

您需要處理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 +
                 ".";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM