gpt4 book ai didi

c# - Asp.net Dropdownlist 选中项值

转载 作者:行者123 更新时间:2023-11-30 20:41:37 24 4
gpt4 key购买 nike

DropDownList 中的 SelectedItem 有问题

<asp:DropDownList ID="Etkin_Drop" runat="server" OnSelectedIndexChanged="Etkin_Drop_SelectedIndexChanged">
<asp:ListItem Text="Seç" Value="-1" Selected="True"></asp:ListItem>
<asp:ListItem Text="Aktif" Value="1"></asp:ListItem>
<asp:ListItem Text="Deaktif" Value="0"></asp:ListItem>
</asp:DropDownList>

第一个列表项值是 -1 但是当我想检查 if 语句时它不起作用

protected void Etkin_Drop_SelectedIndexChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(Etkin_Drop.SelectedItem.Value) == -1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Lütfen Bir Seçim Yapınız');", true);
}
else
{
Label4.Text = Etkin_Drop.SelectedItem.Value;
}
}

我无法定义问题

最佳答案

AutoPostBack 属性添加到您的 DropDownList 并将此属性设置为 True。像这样:

<asp:DropDownList ID="Etkin_Drop" runat="server" 
OnSelectedIndexChanged="Etkin_Drop_SelectedIndexChanged" AutoPostBack="True">

关于c# - Asp.net Dropdownlist 选中项值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com