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();
}`

有什么我做错了吗?

4

1 回答 1

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 +
                 ".";
}
于 2013-10-24T17:56:17.740 回答