在dropdownlist selectedindex更改后显示隐藏的文本框和标签

时间:2013-03-17 20:38:53

标签: c# sharepoint

C#代码:

    protected void DropDownListDB_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownListDB.SelectedValue == "Other")
        {
            LabelIfOtherDb.Visible = true;
            TextBoxIfOtherDb.Visible = true;
        }
    }

ASP代码:

                <asp:DropDownList AutoPostBack="True" ID="DropDownListDB" runat="server" Height="20px" 
                    Width="158px">
                    <asp:ListItem>- Select -</asp:ListItem>
                    <asp:ListItem>Oracle</asp:ListItem>
                    <asp:ListItem>MS SQL Server</asp:ListItem>
                    <asp:ListItem>MySQL</asp:ListItem>
                    <asp:ListItem>MS Access</asp:ListItem>
                    <asp:ListItem>Other</asp:ListItem>
                </asp:DropDownList>

我有AutoPostBack="True",但它仍然没有显示我隐藏的文本框/标签..有什么建议吗?

2 个答案:

答案 0 :(得分:4)

看来,您的事件未连接到事件处理程序。 两种可能性:或者,在Markup中定义事件处理程序,如:

<asp:DropDownList AutoPostBack="True" ID="DropDownListDB" runat="server" Height="20px" SelectedIndexChanged="DropDownListDB_SelectedIndexChanged">

或代码隐藏

DropDownListDB.SelectedIndexChanged += DrowpDownListDB_SelectedIndexChanged;

你应该把它放在标记中。

答案 1 :(得分:0)

这项工作对大学作业有同样的问题

    <asp:DropDownList ID="DropDownList1" AutoPostBack="true" 
    runat="server" Height="16px" Width="237px" 
    onselectedindexchanged="DropDownList1_SelectedIndexChanged"/>
相关问题