• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

recordset in table - make every second row a different colour

Hi,

Using the following code, how do I make every second row have a bgcolor #cccccc. Is it detecting an odd/even count number or is there and easier way.

<table>
<tr>
rs sql, cn
while not rs.eof
<td><%= rs("field") %></td>
rs.movenext
wend
</tr>
</table>

Thanks,

t
0
mrduckers
Asked:
mrduckers
  • 3
  • 2
  • 2
2 Solutions
 
Anthony PerkinsCommented:
<table>
<tr>
rs sql, cn
Dim Row
Row = 1
while not rs.eof
     If Row Mod 2 = 0 Then  'Add bgcolor #cccccc attribute here
              <td><%= rs("field") %></td>
     Else
              <td><%= rs("field") %></td>
     End
    rs.movenext
    Row = Row + 1
wend
</tr>
</table>
0
 
Dirar Abu KteishCommented:
a small correction on acperkins code, on every two rows not columns, so here is the code that do that:

response.write "<table>"
rs sql, cn
Dim Row
Row = 1
while not rs.eof
     If Row Mod 2 = 0 Then
          response.write "<tr style=""background-color:#cccccc;"">"
     Else
          response.write "<tr>"
     End
     response.write "<td>" & rs("field")  & "</td>"
     rs.movenext
     Row = Row + 1
     response.write "</tr>"
wend
response.write "</table>"
0
 
Anthony PerkinsCommented:
>>a small correction on acperkins code, on every two rows not columns<<
A big correction.  That will teach me not to just copy and paste. Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dirar Abu KteishCommented:
welcome ;)
0
 
mrduckersAuthor Commented:
what points split do you guys want?
0
 
Anthony PerkinsCommented:
50-50 is fine with me.
0
 
mrduckersAuthor Commented:
increase to 300
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now