62,254
社区成员
发帖
与我相关
我的任务
分享
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Width="120px" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="0">a</asp:ListItem>
<asp:ListItem Value="1">b</asp:ListItem>
</asp:DropDownList>
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="120px" Text="我是文本框"></asp:TextBox>
<asp:DropDownList ID="DropDownList2" Width="120px" runat="server">
<asp:ListItem Value="0">我是下拉框</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.Visible = true;
this.DropDownList2.Visible = false;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 0)
{
this.TextBox1.Visible = true;
this.DropDownList2.Visible = false;
}
else if (DropDownList1.SelectedIndex == 1)
{
this.TextBox1.Visible = false;
this.DropDownList2.Visible = true;
}
}