Alternating Table Row Color in Classic ASP

Posted on

This is a nifty trick that’s I’ve used for a while. You can use this code while looping through data, for example, writing a list of names and numbers. Every other row will reference the alternating color on a style sheet.
<code>
if (intRowCounter mod 2) = 1 then
Response.Write “”
else
Response.Write “<tr>”
end if

intRowCounter = intRowCounter + 1 </tr></code>
We use the vbscript mod function to determine if the row counter is an even or odd number. If it’s not even, use the alternate color (using a stylesheet here).

Enjoy!