我对SelectedItem
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>
第一个列表项值是-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;
}
}
我无法定义问题
答案 0 :(得分:4)
将AutoPostBack
属性添加到DropDownList
并将此属性设置为True
。像这样:
<asp:DropDownList ID="Etkin_Drop" runat="server"
OnSelectedIndexChanged="Etkin_Drop_SelectedIndexChanged" AutoPostBack="True">