• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

如果使用C#选择了dropdownlist值,则显示div

用户头像
it1352
帮助1

问题说明

如果在下拉列表中选择了特殊的选项",我正在尝试使Div出现.无论我尝试什么,我都无法使其正常工作.我在这里尝试了其他页面,但似乎没有任何作用.

I'm trying to make a Div appear if special "option" is selected in a Drop Down list. No matter what I try I can't make it work. I tried other pages here but nothing seems to make it work.

我的C#代码

protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlEmne.SelectedValue == "Lej os")
    {
        divselected.Visible = true;
    }
    if (ddlEmne.SelectedValue == "")
    {
        divselected.Visible = false;
    }
}

我的DropDownList:

My DropDownList:

<asp:DropDownList CssClass="margtop"    runat="server" OnSelectedIndexChanged="ddlSubject_SelectedIndexChanged">
                <asp:ListItem Value="Pakke Løsninger">Pakke Løsninger</asp:ListItem>
                <asp:ListItem Value="Spørgsmål">Spørgsmål</asp:ListItem>
                <asp:ListItem Value="Lej os">Lej os</asp:ListItem>
                <asp:ListItem Value="Andet">Andet</asp:ListItem>
            </asp:DropDownList>

和我要显示/隐藏的div:

and the div I want to show/hide :

<div   runat="server" style="visibility: hidden;">
    s
</div>

希望有人可以说我做错了.

Hope that someone can say that I'm doing wrong.

正确答案

#1

您需要启用下拉列表的AutoPostBack以便在服务器端引发 OnSelectedIndexChanged 事件.

You need to Enable the AutoPostBack of the dropdownlist for raising the OnSelectedIndexChanged event on server side.

asp:DropDownList CssClass="margtop"   AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlSubject_SelectedIndexChanged">

并更改标记:可见是html元素的属性,因此您可以像这样直接使用它.

and change the markup: visible is the attribute of html elements, so you can directly use it like this.

 <div   runat="server" visible="false">
    s
 </div>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfggaj
系列文章
更多 icon
同类精品
更多 icon
继续加载