无法使用SelectedIndexChanged(DropDownList)[duplicate]更新Web应用程序中的更改

问题描述 投票:0回答:1

因此,我编写了一个程序,其中将下拉列表中城市名称的字母数乘以某个常数。但是它不会更新。

这里是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>

这里是c#代码:

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

            Price.Text = price.ToString();
        }

P.S。我已将项目添加到c#中,而不是html中。

c# type-conversion listitem selectedindexchanged
1个回答
0
投票

来自Why event not fired when I change selection on DropDownList?

您需要在AutoPostBack中将True属性设置为DropDownList,如下所示:

<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>
© www.soinside.com 2019 - 2024. All rights reserved.