[英]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.