You are here: Re: How to Alternate Table Row Colors in CSS and HTML « HTML « IT news, forums, messages
Re: How to Alternate Table Row Colors in CSS and HTML

Posted by John Smith on 10/15/43 11:23

Adrienne wrote:
> Gazing into my crystal ball I observed John Smith <noone@nowhere.net>
> writing in news:W8udnajJNKhJIWvfRVn-2Q@comcast.com:
>
>
>>http://www.somacon.com/p338.php
>>How to Alternate Table Row Colors in CSS and HTML
>>
>>I just completed this article. Comments welcome!
>
>
> For the ASP, this is a little cleaner, no need for confusing
> response.writes:
>
> <table>
> <% while not rs.EOF
> c = c + 1
> if c mod 2 = 0 then
> theclass = "colora"
> else
> theclass = "colorb"
> end if
> %>
> <tr class="<%=theclass%>">
> <td><%=data%></td>
> </tr>
> <% rs.Movenext
> wend
> rs.Close
> set rs = nothing
> %>
> </table>
>
> Then define colora and colorb either in the style element or in an
> external stylesheet.
>

Yeah, that's how I used to write my loops, but I improved it to the
method in my article. Using response.write has some advantages in that
it preserves the indentation of your code, and it may be somewhat easier
to migrate to any future language.

Using "colora" and "colorb" as the class names is specifically to be
avoided as I pointed out in my article. Names like "c0" and "c1" would
be shorter and result in shorter HTML output. Exactly as I pointed out
in my article, your method takes several lines to alternate the class
name, whereas my method can be done inline.

Furthermore, if you use "mod" instead of "and", you are doing the
equivalent of a division operation on every loop iteration. "Mod" takes
dozens of CPU cycles whereas "and" typically takes only one. When I
tested ASP performance, I noticed the time difference on long loops.
ASP doesn't optimizes the expression (c Mod 2 = 0) automatically. Many
people need their pages to run as fast as possible.

Thanks for your comments.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация