Fun Infused Games  |   Smooth Operator RSS 

  Home   |    Archive   |    Subscribe   |    Search   |    About
Posts prior to 8/2/2010 may be missing data. If you need one of those posts, please contact and I will try and recover/find it.

Hiding a Table Column Using
Date 7/7/2010    Tags    (0)

Recently I found the need to hide a full column in an HTML table based on some information determined on the server. This turns out to be rather straightforward to do but since I had a difficult time locating code to do just that, I figured I'd share.

First off, you need to add an ID and the runat attribute to you table so that you can access them server-side.
<table id="tblMyTable" runat="server" >
    <td>Cell 1</td>
    <td>Cell 2</td>
Now in your code behind, just do a simple loop through each of the rows and hide the appropriate cells (hiding the same cell in each row effectively creates a hidden column). Assuming you want to hide the first column in your table (zero indexed), the code would look a little something like this.
foreach (HtmlTableRow thisRow in this.tblMyTable.Rows)
    thisRow.Cells[0].Visible = false;
Here's one gotcha to watch out for... HTML tables are just HTML tables. Adding the runat attribute allows you to manipulate them server-side but you'll get an error if your table includes an controls. If that is the case, you'll have to do something else such as using an ASP table object instead. /tds/g

This article has been view 4041 times.


No comments for this article.

Add Comments

Name *
  Name the animal in the picture below:

Comment *
Insert Cancel

Xbox (1)  C# (14)  Visual Studio (1)  Cool (2)  iOS (3)  PC (1)  Rant (50)  Sports (11)  XBLIG (32)  Abduction Action (1)  Design (2)  Fin (1)  Volchaos (11)  VolChaos (1)  Nastier (4)  Game Dev (11)  Abdction Action! (1) (18)  Nasty (34)  SQL (1)  XNA (40)  World of Chalk (2)  Video Games (7)  Web (19)  Abduction Action! (27)  Hypership (28)  WP7 (8)  Advise (14)  FIN (20)  Trivia or Die (3)  Development (13)  Absurd (2)  Trivia Or Die (1)