簡體   English   中英

Asp.net Dropdownlist選擇的項目值

[英]Asp.net Dropdownlist selected item value

我在DropDownListSelectedItem有問題

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM