Reputation: 833
I have a dropdown in which I am adding list items dynamically. I set autopostback to true, but nothing seems to happen when I select an item in dropdown.
Mark Up
`<asp:DropDownList runat="server" AutoPostBack="true" ID="restaurant_city_con" CssClass="selectboxindex"></asp:DropDownList>`
Code Behind
`if (!this.IsPostBack)
{
addStates();
showData();
dashboardPageFunction();
ordersPageFunction();
reportsPageFunction();
categoriesPageFunction();
menuPageFunction();
offersPageFunction();
bookingPageFunction();
}
else
{
addCities();
addZipCode();
}`
Is there anything I am doing wrong ?
Upvotes: 0
Views: 1126
Reputation: 34846
You need to handle the OnSelectedIndexChanged
event, like this:
Markup:
<asp:DropDownList runat="server" AutoPostBack="true" ID="restaurant_city_con"
CssClass="selectboxindex"
OnSelectedIndexChanged="restaurant_city_con_SelectedIndexChanged">
</asp:DropDownList>
Code-behind:
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 +
".";
}
Upvotes: 2