我希望能够根据用户从下拉列表中选择的请求类型(也包含在表单中)来包含和排除表单的某些部分。这是我当前的代码。我可以使文本框消失,但我无法使标签消失。
<div>
<table>
<tr>
<td>
<font color="red">*</font>MAC Request Type:
</td>
<td>
<asp:DropDownList ID="ddlMACRequestType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlMACRequestType_Change">
<asp:ListItem Text="Select One" Value=""></asp:ListItem>
<asp:ListItem Text="Add Device" Value="Add Device"></asp:ListItem>
<asp:ListItem Text="Change Device" Value="Change Device"></asp:ListItem>
<asp:ListItem Text="Delete Device" Value="Delete Device"></asp:ListItem>
<asp:ListItem Text="Alert Change" Value="Alert Change"></asp:ListItem>
<asp:ListItem Text="Other" Value="Other"></asp:ListItem>
</asp:DropDownList>
<asp:CheckBox ID="chkbxLiveSearch" runat="server" Visible="false" Checked="true" AutoPostBack="true" OnCheckedChanged="chkbxLiveSearch_Change" Text=" Use Live Search" />
</td>
</tr>
<tr>
<td>
<font color="red">*</font>Device:
</td>
<td>
<asp:TextBox ID="txtDevice" runat="server" MaxLength="255" width="375" ClientIDMode="Static"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<font color="red">*</font>Interface:
</td>
<td>
<asp:TextBox ID="txtInterface" runat="server" MaxLength="255" width="375" ClientIDMode="Static"></asp:TextBox>
</td>
</tr>
有人建议我使用 asp:label,但是我该如何添加红色星号呢?它们对于该项目很重要。这是有人建议的,但没有按预期工作。
<asp:Panel Visible="false">
<td>
<font color="red">*</font>Device:
</td>
<td>
<asp:TextBox ID="txtDevice" runat="server" MaxLength="255" width="375" ClientIDMode="Static"></asp:TextBox>
</td>
</asp:Panel>
最佳答案
为了隐藏标签,请创建 <asp:Label>
为了它。这将为您提供类似于 <asp:TextBox>
的服务器端功能。 .
为了让事情变得更简单,我经常倾向于使用 <asp:Panel>
。这本质上是服务器端<div>
并且使您能够同时隐藏许多内容,而不是单独隐藏所有内容。
这也不会留下一堆空的表格行和单元格到处都是。
<asp:Panel ID="pnlDevice" runat="server">
<tr>
<td>
<font color="red">*</font>Device:
</td>
<td>
<asp:TextBox ID="txtDevice" runat="server" MaxLength="255" width="375" ClientIDMode="Static"></asp:TextBox>
</td>
</tr>
</asp:Panel>
然后像其他控件一样隐藏面板。
pnlDevice.Visible = false;
关于asp.net - 根据下拉列表中的选择删除网络表单的某些部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30357856/