Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide column of table with codebehind

Tags:

html

c#

asp.net

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?

like image 401
CodeMonkey1313 Avatar asked Jan 23 '23 09:01

CodeMonkey1313


2 Answers

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>
like image 94
John Rasch Avatar answered Jan 31 '23 18:01

John Rasch


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";
        }
    }
like image 27
Xtian11 Avatar answered Jan 31 '23 19:01

Xtian11