I have a (html)table (sample layout below) that I'd like to hide the last two columns under certain conditions, using the C# codebehind. I'd prefer not to do this by shrinking the width of the columns to 0, though I'm not ruling it out. There aren't any CSS classes really supplied to most of the rows and none of the columns. I've tried using a colgroup to set the display to none as well as the visibility to hidden on the colgroup, but with no luck.
_____________
|__|__|__|__|
|__|__|__|__|
|__|__|__|__|
to
_______
|__|__|
|__|__|
|__|__|
Any thoughts?
Assuming your table is static, you could dynamically apply a CSS class
to any columns you want hidden:
<table>
<tr>
<th>
Visible
</th>
<th class="<%= HiddenClassName %>">
Possibly hidden
</th>
</tr>
<tr>
<td>
Visible
</td>
<td class="<%= HiddenClassName %>">
Possibly hidden
</td>
</tr>
</table>
In the code file, your property could be:
public string HiddenClassName { get; private set; }
The hidden
style itself:
<style type="text/css">
.hidden
{
visibility: hidden;
display: none;
}
</style>
In the aspx:
<table>
<tr>
<td style="<%= HiddenClassName %>">
my content to be hidden
</td>
</tr>
</table>
In the Code:
public class OPMRESRVA0 : System.Web.UI.Page
{
public string HiddenClassName { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
HiddenClassName = "display:none";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With