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"
,但它仍然不显示隐藏的文本框/标签。 最佳答案
看来,您的事件未连接到事件处理程序。
两种可能性:要么在标记中定义事件处理程序,例如:
<asp:DropDownList AutoPostBack="True" ID="DropDownListDB" runat="server" Height="20px" SelectedIndexChanged="DropDownListDB_SelectedIndexChanged">
或在后面的代码中
DropDownListDB.SelectedIndexChanged += DrowpDownListDB_SelectedIndexChanged;
您应该将其标记出来。
关于c# - 在选择下拉列表后更改索引后显示隐藏的文本框和标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15465945/