我有一个简单的问题。我在互联网上研究,但我找不到明确的解决方案。我在可能页面中有一个下拉列表,我想显示或隐藏某些内容取决于其选择的索引更改。我有这段代码,我确信这段代码应该可以工作,因为我多次这样写:
<div class="icerik-tablo">
<div>
<h3>Telefon Bilgileri</h3>
<div class="ekle"><a href="javascript:;" onclick="ekle_goster('ekle_telefon')">Ekle</a></div>
<div class="clear"></div>
<div class="pop" id="ekle_telefon" style="display:none;">
<asp:UpdatePanel ID="upTelefon" runat="server">
<ContentTemplate>
<div>
<asp:DropDownList ID="ddlTelefonTipi" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTelefonTipi_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvTelefonTipi" runat="server" ControlToValidate="ddlTelefonTipi" ErrorMessage="*" ValidationGroup="telefonEkle"></asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlTelefonErisimTipi" runat="server" AutoPostBack="true"></asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvTelefonErisimTipi" runat="server" ControlToValidate="ddlTelefonErisimTipi" ErrorMessage="*" ValidationGroup="telefonEkle"></asp:RequiredFieldValidator>
<asp:CheckBox ID="cbTelefonBirincil" runat="server" Text="Birincil Yap" />
</div>
<br /><br />
<div class="islem">
<asp:Button ID="btnTelefonEkle" runat="server" Text="Ekle" />
<a href="javascript:;" onclick="ekle_gizle('ekle_telefon')">İptal</a>
</div>
<div class="clear"></div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
这些是我的页面代码。C# 代码在这里:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TelefonTipiBagla();
TelefonErisimTipiBagla();
}
}
protected void TelefonTipiBagla()
{
ddlTelefonTipi.DataSource = Telefon.StringTelefonTipi;
ddlTelefonTipi.DataBind();
ddlTelefonTipi.Items[0].Value = "";
}
protected void TelefonErisimTipiBagla()
{
ddlTelefonErisimTipi.DataSource = IletisimBaseClass.StringIzinTipi;
ddlTelefonErisimTipi.DataBind();
ddlTelefonErisimTipi.Items[0].Value = "";
}
protected void ddlTelefonTipi_SelectedIndexChanged(object sender, EventArgs e)
{
if ((Telefon.TelefonTipi)ddlTelefonErisimTipi.SelectedIndex == Telefon.TelefonTipi.CepTelefonu || (Telefon.TelefonTipi)ddlTelefonErisimTipi.SelectedIndex == Telefon.TelefonTipi.Faks)
{
string val = ddlTelefonErisimTipi.SelectedValue;
tbTelefonDahili.Visible = false;
lblTelefonTire.Visible = false;
lblTelefonDahili.Visible = false;
}
else
{
string val = ddlTelefonErisimTipi.SelectedValue;
tbTelefonDahili.Visible = true;
lblTelefonTire.Visible = true;
lblTelefonDahili.Visible = true;
}
}
问题是下拉列表选择的索引总是为零(0)。所以,我的代码不能正常工作。请帮助我,我确定我错过了一些东西。感谢您的帮助。