...

View Full Version : Alternate Rows, different colours



christrinder
02-27-2003, 02:01 PM
What is the best way to display the results of a research or db enquiry in alternately colour table cell rows. I.e. if you look at the pages in these forums, the colour of the box is changed every other box to help make a distinction between the rows. if I have two different style sheet cells set-up, how do I dictate which they use. Hope that makes sense.

arnyinc
02-27-2003, 02:26 PM
Untested code, but it's pretty short so I probably didn't make any errors. Another way to do it is to have two RS.MOVENEXT statements in each iteration of your WHILE loop and test to make sure you haven't gone past the end of the recordset after the second RS.MOVENEXT each time.

<%
color="red"

WHILE NOT RS.EOF

if color="red" then
response.write "<font color=""red"">"&RS("fieldname")&"</font>"
color="blue"
else
response.write "<font color=""blue"">"&RS("fieldname")&"</font>"
color="red"
end if

RS.MOVENEXT
WEND
%>

raf
02-27-2003, 02:30 PM
Has been treated before in previous threads.
I just devide “rownumber” by 2 and then check if it’s 0
Example code



dim row
row = "0"
response.write("<table border='0' cellpadding='5' cellspacing='0' width='95%'>")
response.write("<tr><td><b>Select a table:</b></td><td align='right'><a href='adminmain.asp'>Back to Admin-mainpage</a></td></tr>")
response.write("<tr bgcolor='#415FF8'><td><b>Tables</b></td><td><b>Numer of variables in table</b></td></tr>")
do while rsTables.EOF=false
‘##############################################”
if row MOD 2 = 0 then 'alternating backgroundcolours
response.write("<tr bgcolor='#AAC7FF'>")
else
response.write("<tr bgcolor='#AFEEEE'>")
end if
‘################################################
response.write("<td><a href=admin_defineview.asp?Table=" &rsTables.Fields("TableName") & ">" & server.HTMLEncode (rsTables.Fields("TableName")) &"</a></td>")
response.write("<td>" & rsTables.Fields("numvar") &"</td>")
response.write("</tr>")
row = row+1
rsTables.MoveNext
loop

christrinder
02-27-2003, 02:32 PM
Cheers guys. Your solutions are along the lines of what I was trying to write but you've certainly helped me along with this. Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum