I tried this, but could not get through:-
code behind
protected HtmlTableRow trComment;
protected void Page_Load(object sender, EventArgs e)
{
//Show/Hide table rows (TR)
trComment.Visible = ConfigUtil.DisplaySummaryComment;
}
.ascx page
<tr id="trComment" runat="server">
<td style="vertical-align:top; text-align:left;">
<%#ConfigUtil.FieldLabels["PIComments"]%>
:
</td>
<td>
<%= Test.Comment %>
</td>
</tr>
A hidden attribute on a <tr> tag hides the table row. Although the table row is not visible, its position on the page is maintained.
Add a runat="server" attribute to the <td> for Column 10 and give it an ID (like id="column10Header" ). Then you can set its Visible property to false .
Your original code doesn't work, not because it's incorrect, but because you probably have more places with trComment
(in which case it should error) or because your current code is inside a template of some sort (in a GridView
, a Repeater
). The latter is most likely, because you use a data-statement (<%#
), which is commonly placed in a databound control template (but not necessarily).
One way to solve this uniformly and easily (many ways exist and it's probably best not to use literal tables anyway) is to use an asp:PlaceHolder
, which does not leave HTML "traces", but can be used to toggle any block of HTML / ASP.NET code:
<!-- toggle through OnLoad (can use ID as well) -->
<asp:PlaceHolder runat="server" OnLoad="MakeVisibleOrNot">
<tr>
...
</
</asp:PlaceHolder>
in the code behind
protected void MakeVisibleOrNot(object sender, EventArgs e)
{
((Control) sender).Visible = ConfigUtil.DisplaySummaryComment;
}
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