Table with alternate color rows

# Thread: Table with alternate color rows

1. Lee Pooi Ling Guest

## Table with alternate color rows

How can I generate a table from database with alternate color rows.<BR><BR>For example :<BR><BR>row 1 : yellow color<BR>row 2 : red color<BR>row 3 : yellow color<BR>row 4 : red color

2. Member
Join Date
Dec 1969
Posts
35

## RE: Table with alternate color rows

hi, no the best idea, but as u retrieve a row, u add to a counter, if the counter is odd, then yellow, if counter is even then red colour . how&#039s that ????<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
940

## RE: Table with alternate color rows

Yes - this is correct. Along those same lines try:<BR><BR>&#060;table&#062;<BR>Counter = 0 <BR>&#060;%<BR>Do While NOT rs.EOF<BR>If Counter mod 2 = 0 Then<BR>Response.Write "&#060;TR&#062;&#060;TD bgcolor=Yellow&#062;Text&#060;/TD&#062;&#060;/TR&#062;"<BR><BR>Else<BR><BR>Response.Write "&#060;TR&#062;&#060;TD bgcolor=Red&#062;Text&#060;/TD&#062;&#060;/TR&#062;"<BR><BR>End If<BR>Counter = Counter + 1 <BR>rs.MoveNext<BR>Loop<BR>%&#062;<BR>&#060;/table&#062;

4. Michael Swanson Guest

## RE: Table with alternate color rows

There are actually a couple of ways to do this effectively. Using a counter certainly works, but it also opens up the possibility for exceeding that variable type&#039s maximum storage capacity (not that this would happen, but we code for things that might not ever happen).<BR><BR>The first way would be very simple:<BR><BR>If sColor = "Red" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;sColor = "Yellow"<BR>Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;sC olor = "Red"<BR>End If<BR><BR>If we only have two options, this method usually works fine. Of course, you have to seed sColor with a starting color.<BR><BR>The method I generally prefer is the following:<BR><BR>iToggle = 1 - iToggle<BR>If iToggle = 1 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;sColor = "Red"<BR>Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;sColo r = "Yellow"<BR>End If<BR><BR>Assuming iToggle starts out at zero (which it will in most languages), you don&#039t have to seed this, and it will work for any toggled situation. On top of that, it&#039s integer arithmetic and won&#039t exceed the variable type&#039s maximum storage capacity.<BR><BR>Hope this helps...<BR><BR>Michael Swanson, MCSE, MCP+Internet<BR>Webmaster<BR>Donnelly Corporation<BR>mike.swanson@donnelly.com<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•