Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want Every Column Different Colors 1

Status
Not open for further replies.

Rexolio

Technical User
Aug 29, 2001
230
0
0
I have posted some code that I am using below. I have a table with 3 columns that pulls info from my database. I want each column to be a different color. The code I've pasted below works. The problem is I have to tell each column "If i = 1 OR i = 4 OR ...." This could be a REALLY LONG string, especially considering that there could be as many as 50,000 records!!! I'm looking for an easier way to do it:

<table border=&quot;0&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>

<tr>
<%
i = 1
do until rsResults.eof
cellString1 = &quot;<td width='33%' valign='top' bgcolor='#FFFF00'><font size='2' face='Arial'>&quot; & rsResults(&quot;strName&quot;) & &quot;<br>&quot; & rsResults(&quot;strAddress&quot;) & &quot;<br>&quot; & rsResults(&quot;strCity&quot;) & &quot;, &quot; & rsResults(&quot;strState&quot;) & &quot; &quot; & rsResults(&quot;strZip&quot;) & &quot;</font></td>&quot;
cellString2 = &quot;<td width='33%' valign='top' bgcolor='#00FF00'><font size='2' face='Arial'>&quot; & rsResults(&quot;strName&quot;) & &quot;<br>&quot; & rsResults(&quot;strAddress&quot;) & &quot;<br>&quot; & rsResults(&quot;strCity&quot;) & &quot;, &quot; & rsResults(&quot;strState&quot;) & &quot; &quot; & rsResults(&quot;strZip&quot;) & &quot;</font></td>&quot;
cellString3 = &quot;<td width='34%' valign='top' bgcolor='#00FFFF'><font size='2' face='Arial'>&quot; & rsResults(&quot;strName&quot;) & &quot;<br>&quot; & rsResults(&quot;strAddress&quot;) & &quot;<br>&quot; & rsResults(&quot;strCity&quot;) & &quot;, &quot; & rsResults(&quot;strState&quot;) & &quot; &quot; & rsResults(&quot;strZip&quot;) & &quot;</font></td>&quot;
if i = 1 OR i = 4 OR i = 7 OR i = 10 OR i = 13 OR i = 16 OR i = 19 OR i = 22 OR i = 25 OR i = 28 OR i = 31 OR i = 34 OR i = 37 OR i = 40 OR i = 43 OR i = 46 OR i = 49 OR i = 52 OR i = 55 OR i = 58 OR i = 61 OR i = 64 OR i = 67 OR i = 70 OR i = 73 OR i = 76 OR i = 79 OR i = 82 OR i = 85 OR i = 88 OR i = 91 OR i = 94 OR i = 97 then
response.write(cellString1)
else
if i = 2 OR i = 5 OR i = 8 OR i = 11 OR i = 14 OR i = 17 OR i = 20 OR i = 23 OR i = 26 OR i = 29 OR i = 32 OR i = 35 OR i = 38 OR i = 41 OR i = 44 OR i = 47 OR i = 50 OR i = 53 OR i = 56 OR i = 59 OR i = 62 OR i = 65 OR i = 68 OR i = 71 OR i = 74 OR i = 77 OR i = 80 OR i = 83 OR i = 86 OR i = 89 OR i = 92 OR i = 95 OR i = 98 then
response.write(cellString2)
else
if i mod 3 = 0 then
response.write(cellString3)
%>
</tr>
<tr>
<%
end if
end if
end if

i = i + 1
rsResults.movenext
loop
%>

</table>

Thanks in advance for any assistance!!!

Rexolio
rexolio@bellsouth.net
 
If you insist on displaying your records from left to right, 1-2-3 on line #1, 4-5-6 on line #2, and so on, I see your frustration. This would shorten your code a little bit.

Instead of writing three separate html codes, do something like this...

<%
dim bcolor

if i = 1 OR i = 4 OR i = 7 OR i = 10 OR i = 13 OR i = 16 OR i = 19 OR i = 22 OR i = 25 OR i = 28 OR i = 31 OR i = 34 OR i = 37 OR i = 40 OR i = 43 OR i = 46 OR i = 49 OR i = 52 OR i = 55 OR i = 58 OR i = 61 OR i = 64 OR i = 67 OR i = 70 OR i = 73 OR i = 76 OR i = 79 OR i = 82 OR i = 85 OR i = 88 OR i = 91 OR i = 94 OR i = 97 then
bcolor = &quot;#0000FF&quot;
else
if i = 2 OR i = 5 OR i = 8 OR i = 11 OR i = 14 OR i = 17 OR i = 20 OR i = 23 OR i = 26 OR i = 29 OR i = 32 OR i = 35 OR i = 38 OR i = 41 OR i = 44 OR i = 47 OR i = 50 OR i = 53 OR i = 56 OR i = 59 OR i = 62 OR i = 65 OR i = 68 OR i = 71 OR i = 74 OR i = 77 OR i = 80 OR i = 83 OR i = 86 OR i = 89 OR i = 92 OR i = 95 OR i = 98 then
bcolor = &quot;#00FFFF&quot;
else
if i mod 3 = 0 then
bcolor = &quot;#FFFFFF&quot;
%>

<td width='34%' valign='top' bgcolor='<%=bcolor%>'>
<font size='2' face='Arial'>
<%=rsResults(&quot;strName&quot;)%><br>
<%=rsResults(&quot;strAddress&quot;)%><br>
<%=rsResults(&quot;strCity&quot;)%>, <%=rsResults(&quot;strState&quot;)%>
etc.....

However, if you don't mind displaying your record results from top to bottom 1-2-3-4-5 down column 1, 6-7-8-9-10 down column 2, etc... (Which I would recommend) then do something like this.

<table>
<tr>
<td bgcolor=&quot;column1color&quot;>
<table>
<tr>
<td> Record #1 </td>
</tr>
<tr>
<td Record #2 </td>
</tr>
</table>
</td>
<td bgcolor=&quot;column2color&quot;>
<table>
<tr>
<td> Record #3 </td>
</tr>
<tr>
<td Record #4 </td>
</tr>
</table>
</td>

.. and so on

</tr>
</table>

You're going to need to get creative and have ASP do some math with the number of records in the record set to know when to break out of a loop and go to the next column.

TW
 
TW,

Thanks for the suggestion, but your latter comment is what I'm looking for! :) Obviously I need to go from left to right or else I wouldn't do it! The current set up where I'm going to have to type in the numbers up to the possible end number of records (50,000 or more) is definitely the cause of my frustration. I know that there must be a way of doing some fancy math, but I'm not sure how. I'd appreciate any other suggestions you might have or anyone else!!!

Thanks,
Rexolio
 
Why not:
Code:
If i mod 3 = 0 Then
   bcolor = &quot;#FFFFFF&quot;
ElseIf (i+1) mod 3 = 0 Then
   bcolor = &quot;#00FFFF&quot;
Else
   bcolor = &quot;#0000FF&quot;
End If
?
 
This is what I use..

<%
alternate = 0

for i = 0 to uBound(arrayName,2)

if alternate = 0 then
color= &quot;red&quot;
alternate = 1
else
color= = &quot;blue&quot;
alternate = 0
end if
%>
<tr>
<td bgcolor=&quot;<%=color%>&quot;><%=arrayName(0,i)%></td>
<td bgcolor=&quot;<%=color%>&quot;><%=arrayName(1,i)%></td>
</tr>
<%
next
%>

I use arrays, but it doesnt really make a difference to changing the color.

Good luck
 
Thanks dilanttante!!!

That worked like a charm!!!

Sincerely,
Rexolio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top