我有一个下拉列表,我在其中动态添加列表项。我将autopostback设置为true,但是当我在下拉列表中选择一个项目时,似乎没有任何事情发生。
Mark Up
`<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 :(得分: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 +
".";
}