Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Loughborough (UK)
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alternate Rows, different colours

    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.

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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
    %>

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Has been treated before in previous threads.
    I just devide “rownumber” by 2 and then check if it’s 0
    Example code

    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

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Loughborough (UK)
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thank you!

    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!


  •  

    Posting Permissions

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