因此,我编写了一个程序,其中将下拉列表中城市名称的字母数乘以某个常数。但是它不会更新。
这里是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中。
来自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>