Asp.net 下拉列表选择的项目值

Asp.net Dropdownlist selected item value

我对 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">