.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.

About these ads

January 31, 2008 - Posted by | ASP.NET, Tips & Tricks

12 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

  8. Worked quite nicely. Thanks!

    Comment by Rob | August 26, 2009 | Reply

  9. can u please post the code. I need it. I cannot access my id from code.

    Comment by Ashwin | September 1, 2009 | Reply

  10. Hi,
    This is a great tips. Thank you so much.

    Comment by Jimmy | May 13, 2012 | Reply

  11. Wonderful! thank you.

    Comment by BatCat | June 21, 2012 | Reply

  12. I have try so many ways, but this one very simple!!

    Comment by rahim | August 21, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: