【问题标题】:Asp.net Dropdownlist selected item valueAsp.net Dropdownlist 选定项值
【发布时间】:2015-08-26 06:46:18
【问题描述】:

我对@9​​87654322@ 中的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;
    }
}

我无法定义问题

【问题讨论】:

  • 您如何确认它不起作用?你试过调试吗?
  • 你能设置一个断点并检查你得到的值而不是 -1 吗?
  • 是的,我确认了,脚本管理器应该发出警告,但它不会进入 if 语句

标签: c# asp.net drop-down-menu


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    相关资源
    最近更新 更多