Differant colored Rows

1. Kris dawg in the house Guest

## Differant colored Rows

I&#039;ve seen this done before, so it can&#039;t be all that hard. What I want is for the even numbered rows in my table to be slightly lighter than the odd numbered rows. I already have a for loop to create the table, so maybe I could do something with that? Is there a way to check if a number is even or odd? Or does someone have a better suggestion?

2. Beer Ghost Guest

## RE: Different colored Rows

Umm.<BR><BR>for i = 0 to ubound(myarray,2)<BR><BR> &#039;build table<BR> if ((i mod 2) = 0) then <BR> &#039; write diff&#039;t color for text, whatever<BR> end if<BR><BR>next<BR><BR>too complicated?

3. Senior Member
Join Date
Dec 1969
Posts
474

## RE: Differant colored Rows

Here you go:<BR><BR>TheColour = "Blue"<BR>do while not rs.eof<BR>Response.Write "&#060;tr bgcolor=" & TheColour & "&#062;&#060;td&#062;Blah Blah&#060;/td&#062;"<BR>rs.Movenext<BR>If TheColour = "Blue" Then<BR> TheColour = "Red"<BR>Else<BR> TheColour = "Blue"<BR>Loop<BR>

4. Senior Member
Join Date
Dec 1969
Posts
717

## RE: Different colored Rows

Not really... I think I though of a better way though... first check if it&#039;s zero. If it is, print it one color and set the variable to 1. Next time through, if it is one, print that color and set it back to zero.

## RE: Differant colored Rows

I&#039;ve done this a different way, but there is an even/odd way to check. Assuming x is your for...next variable:<BR><BR>if (x mod 2)=0 then<BR> &#039;even<BR> ..color code..<BR>else<BR> &#039;odd<BR> ..color code..<BR>end if

## RE: Different colored Rows

Funny, that&#039;s the way I usually do it, but I was liking your odd even thing :)

7. Senior Member
Join Date
Dec 1969
Posts
717

## RE: Different colored Rows

Even, odd is nice... but probably not the best thing if we ever end up having lots and lots of items selected... then we&#039;d have some rather large numbers.<BR><BR>I was kicking myself about 5 minutes after posting this, that way of check if it&#039;s this color then changing the variable is so simple, I should have thought of it sooner.

8. Senior Member
Join Date
Dec 1969
Posts
1,431

## Or how about negative positive

test=1<BR>for i = 0 to blah<BR>if test&#062;0 Then<BR>color="red"<BR>else<BR>color="blue"<BR>End if<BR>terst=test*-1<BR>next<BR>

9. Senior Member
Join Date
Dec 1969
Posts
1,431

## However

mod is the most flexible, say want 3 colors ,red ,green ,blue in that order<BR><BR>myArr= array("red","green","blue")<BR><BR>for i = 0 to blah<BR>color=amyArr(i mod 3)<BR>next<BR><BR>probably also faster than an if test as if will need to test var types etc.

10. Senior Member
Join Date
Dec 1969
Posts
717

## RE: However

Yes it is definatly more flexible... only takes a second to add in a few new color choices... but then you&#039;d have to be crazy to use lots of colors in a table... really crazy. For two colors, a couple conditional statements works just fine for me.

#### Posting Permissions

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