Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net Dropdownlist selected item value

I have a problem with the SelectedItem in the DropDownList

<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>

First list item value is -1 but when I want to check in the if statement its not working

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;
    }
}

I could not define the problem

like image 450
OykunYenal Avatar asked Mar 04 '26 00:03

OykunYenal


1 Answers

Add AutoPostBack Property to your DropDownList and set this property to True. Like this:

<asp:DropDownList ID="Etkin_Drop" runat="server" 
    OnSelectedIndexChanged="Etkin_Drop_SelectedIndexChanged" AutoPostBack="True">
like image 169
Salah Akbari Avatar answered Mar 05 '26 12:03

Salah Akbari