Reputation: 8404
I have a table with a specific layout. It starts like this:
<table>
<tr bgcolor="#007ACC" style="color:White">
<td width="145"><asp:Label Text="" ID="lblLevel" runat="server" /></td><td width="80"></td><td width="30"></td><td width="145"><asp:Label Text="" ID="lblGroupNumber" runat="server" /></td><td width="60"></td><td width="10">Active</td>
</tr>
<tr>
<td colspan="5">
<asp:TextBox ID="txtName" runat="server" width="460px"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="cboActive" runat="server" Width="50px">
<asp:ListItem>Y</asp:ListItem>
<asp:ListItem>N</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
The problem is, under certain conditions I need it to look like this:
<table>
<tr bgcolor="#007ACC" style="color:White">
<td width="145"><asp:Label Text="" ID="lblLevel" runat="server" /></td><td width="80"></td><td width="30"></td><td width="145"><asp:Label Text="" ID="lblGroupNumber" runat="server" /></td><td width="60"></td><td width="10">Active</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtName" runat="server" width="460px"></asp:TextBox>
</td>
<td></td>
<td colspan="2">
<asp:TextBox ID="txtNumber" runat="server" width="460px"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="cboActive" runat="server" Width="50px">
<asp:ListItem>Y</asp:ListItem>
<asp:ListItem>N</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
I've hidden textboxes before, that's no problem. But the only way I can think of to do this is to hide td's
using code. I've seen this:
How to hide columns in HTML table?
but they never explain how you can determine which td
is to be hidden.
So, can this be done in code (preferably code-behind in C#)? If so, how?
Upvotes: 0
Views: 797
Reputation: 235
Other way to select specific HTML Tags can bei done with css Selectors. http://www.w3schools.com/cssref/css_selectors.asp Look at etc.: p:nth-child(2)
Upvotes: 0
Reputation: 1
You can use LiteralControl and then based on condition change the content or AddControl to the literalcontrol. This can be performed from code behind
Upvotes: 0
Reputation:
In asp.net most elements can be programmatically handled as server controls with runat
set:
<td colspan="2" runat="server" id="tdToHide">
<asp:TextBox ID="txtNumber" runat="server" width="460px"></asp:TextBox>
</td>
In C#:
tdToHide.Visible = false;
This is one of many, many approaches to 'hide things' on a web page.
Another one would be a conditional CSS class on the td
. The display of which would then be dealt with by styles on the page.
Upvotes: 2