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