回发不起作用?

时间:2013-10-24 17:50:54

标签: c# asp.net

我有一个下拉列表,我在其中动态添加列表项。我将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();
}`

我有什么问题吗?

1 个答案:

答案 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 +
                 ".";
}
相关问题