.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

ASP.NET: How To Hide Table Rows In An HTML Table

While I am absolutely an advocate of table-less design, tables are still useful when used correctly. For instance, it is correct to use a table to display tabular data, or to show a form. I came across this extremely simple, but not well-known way to show and hide HTML table rows via the server. Say you have a table:

<table>
<tr>
<td>Hello, World!</td>
<tr>
<tr>
<td>Goodbye, World!</td>
<tr>
</table>

If you want to be able to control your rows on the backend, simply make your <tr> a server tag! I know this seems simple, but at first to me, it appeared counter-intuitive. To do this, change your <tr> to read: <tr id="yourID" runat="server">. Then in your CodeFile you can access its properties, such as yourID.Visible!

Very simple, but hey, the best tricks are.

January 31, 2008 - Posted by Some.Net(Guy) | ASP.NET, Tips & Tricks | | 7 Comments

7 Comments »

  1. your blog provided we little
    necessary info on this topic.
    The post really necessary.

    Comment by Storm | February 21, 2008 | Reply

  2. Good! that wos i needed ! Thank you

    Comment by TarkvaraTehas | July 17, 2008 | Reply

  3. Thanks!

    Comment by Heisa | November 18, 2008 | Reply

  4. wow thanks!!

    Comment by Sy En | November 27, 2008 | Reply

  5. Yeah, wowwowwow! Wond’ring though why u’re against tables, since they seem like a must for a decent layout in web pages.

    Comment by Premy | February 24, 2009 | Reply

  6. thanks, im learning asp .net the hard way, by developing a critical app for our company :( . ive struggling with this for a day and a half, so a big thanks.

    Comment by dean | February 26, 2009 | Reply

  7. Nice and easy. Thanks!!

    Comment by desenfoque | May 15, 2009 | Reply


Leave a comment