ASP - Alternating table row colours

Logan

New Member
Code:
<%
    While Not rsTest.EOF
        Field1 = rsTest.Fields("Field1")
        rsTest.MoveNext
%>
<tr>
    <td style="background-color: #00ff00;"><%=Field1%></td>
</tr>
<%
    Wend
%>

For those of you who don't know, all this code is doing is repeating the table row once for every record in the rsTest recordset.
What I'd like to know, is how do I have the background colour of the cell alternate?

So every second cell could have a background-color: #ff00ff; for instance, while the rest should retain the style as set above.

Thanks in advance for the help.
 

itHighway

New Member
I use following for alternate row color
Private function fncAltRowColor()
fncAltRowColor=""
if NOT intAltRowCount MOD(2) = 0 then
sAltClassName = "style='background-color:#CCCCCC'"
else
sAltClassName = "style='background-color:#CDCDCD'"
intAltRowCount = intAltRowCount + 1
fncAltRowColor = sAltClassName
end function

intAltRowCount = 0
<table>
<tr <%fncAltRowColor%>>
<td>..Text..</td>
<tr>

<tr <%fncAltRowColor%>>
<td>..Text..</td>
<tr>

<tr <%fncAltRowColor%>>
<td>..Text..</td>
<tr>
</table>
 
Last edited:
Top