C# 带有DropDownList的ASP.NET
我将C# 带有DropDownList的ASP.NET,c#,html,asp.net,html-helper,C#,Html,Asp.net,Html Helper,我将工具箱中的DropDownList添加到我正在处理的网站的登录页面 一旦我在下拉列表中选择了一个列表项(在我的例子中,让我们说 例如,健身房…,单击时,我希望在我的下拉列表下方打开三个栏(例如,我们将打开的栏是用户名、密码和ID),我指的是彼此下方的三个文本框 我认为您可以尝试SelectedIndexChanged事件或Javascript来显示文本框,而无需回发。 <select> <option value="1">Gym 1</option> &l
工具箱中的DropDownList
添加到我正在处理的网站的登录页面
一旦我在下拉列表
中选择了一个列表项
(在我的例子中,让我们说
例如,健身房…,单击时,我希望在我的下拉列表下方打开三个栏(例如,我们将打开的栏是用户名、密码和ID),我指的是彼此下方的三个文本框
我认为您可以尝试SelectedIndexChanged事件或Javascript来显示文本框,而无需回发。
<select>
<option value="1">Gym 1</option>
<option value="2">Gym 2</option>
<option value="3">Gym 3</option>
<select>
健身房1
健身房2
健身房3
在firest,您将文本框放在一个窗格中,然后隐藏此面板并
您应该将drobdownlist的Autopostback属性设置为True,在DropDownList中选择一个项目后,将累积回发。因此,您可以显示包含文本框的面板。您可能真正需要的是动态文本框
在html部分:
在代码隐藏中:
void DDL_SelectChanged(object sender, EventArgs e)
{
if (DDL1.SelectedIndex == 1)
{
for (int i = 0; i < 3; i++)
{
TextBox newTB = new TextBox();
newTB.ID = "TB" + i;
PH1.Controls.Add(newTB);
}
}
}
void DDL\u SelectChanged(对象发送方,事件参数e)
{
如果(DDL1.SelectedIndex==1)
{
对于(int i=0;i<3;i++)
{
TextBox newTB=新的TextBox();
newTB.ID=“TB”+i;
PH1.对照品.添加(新B);
}
}
}
您可以使用MultiveView控件。并在下拉列表的selectedIndexChanged事件中设置活动视图索引。
我为您编写了一些示例代码:
ASPx侧:
<asp:MultiView ID="multiView" ActiveViewIndex="-1" runat="server">
<asp:View ID="viewGym" runat="server">
<asp:TextBox ID="txtBxUserName" runat="server" />
<asp:TextBox ID="txtBxPassword" runat="server" />
<asp:TextBox ID="txtBxId" runat="server" />
</asp:View>
</asp:MultiView>
<asp:DropDownList ID="Dropdownlist1" runat="server" AutoPostBack="true"
onselectedindexchanged="Dropdownlist1_SelectedIndexChanged">
<asp:ListItem Text="Choose one club" Value="0" />
<asp:ListItem Text="Gym" Value="1" />
<asp:ListItem Text="Shoppers" Value="2" />
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
{
if ( IsPostBack ) //don't forget :)
return;
}
protected void Dropdownlist1_SelectedIndexChanged( object sender, EventArgs e )
{
if ( Dropdownlist1.SelectedValue == "1" ) //Gym item selected
{
multiView.ActiveViewIndex = 0; //Gym view active
}
}
如果希望在加载第一页时任何视图都不处于活动状态,则在aspx代码中将ActiveViewIndex设置为-1