Bojan Petkovski
Bojan Petkovski

Reputation: 95

Unable to update changes in a web application using SelectedIndexChanged (DropDownList)

So I've written a program where the number of letters of a city name from a drop down list are multiplied to a certain constant. However it doesn't update.

Here is the html:

<asp:DropDownList ID="Destinacii" runat="server" Height="20px" Width="76px" OnSelectedIndexChanged="Destinacii_SelectedIndexChanged"></asp:DropDownList>

Price: <asp:Label ID="Price" runat="server" Text="0"></asp:Label>

Here is the c# code:

protected void Destinacii_SelectedIndexChanged(object sender, EventArgs e)
        {
            string text = Destinacii.SelectedItem.Text;
            int price = (2000 * text.Length);

            Price.Text = price.ToString();
        }

P.S. I've added the items in c#, not in the html.

Upvotes: 0

Views: 24

Answers (1)

CyanCoding
CyanCoding

Reputation: 1037

From Why event not fired when I change selection on DropDownList?:

You need to set the AutoPostBack property to True in your DropDownList like so:

<asp:DropDownList ID="Destinacii" runat="server" Height="20px" Width="76px" OnSelectedIndexChanged="Destinacii_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>

Price: <asp:Label ID="Price" runat="server" Text="0"></asp:Label>

Upvotes: 0

Related Questions