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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping thru records with different td cells

Status
Not open for further replies.

spastica

Programmer
Sep 27, 2002
72
GB
how do i loop through records from a table, but display them so that one cell is white, the next is gray, the next is white etc. so i have a table with different rows of colours alternating between two.

thanks in advance
 
something like this maybe??
Code:
<STYLE>
tr.white {background-color: #FFFFFF;}
tr.grey {background-color: #DDDDDD;}
</STYLE>
</HEAD>

<BODY>
<TABLE>
<%
strColour = &quot;white&quot;

While NOT objRS.EOF
  If strColour = &quot;white&quot; Then
    strColour = &quot;grey&quot;
  Else
    strColour = &quot;white&quot;
  End If

  Response.Write &quot;<TR CLASS=&quot; & strColour & &quot;><TD>&quot; & objRS(&quot;Info&quot;) & &quot;</TD></TR>&quot; & vbcrlf

  objRS.MoveNext
Wend
%>
</TABLE>
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
set up a variable to hold the current colour
apply this as the rowbackground at the start of the loop

at the end of you loop, before you change rows check what the current value is (using an if statement) and change the colour

e.g.(without the loop

<html>
<head>
<title>Untitled</title>
</head>
<body>
<%

dim rowcolour
rowcolour = &quot;white&quot;
response.write &quot;<table border= &quot;&quot;1&quot;&quot;>&quot;
response.write &quot;<tr bgcolor = &quot;+rowcolour+&quot;>&quot;
response.write &quot;<td>Row1</td>&quot;
response.write &quot;</tr>&quot;

rowcolour=&quot;silver&quot;
response.write &quot;<tr bgcolor = &quot;+rowcolour+&quot;>&quot;
response.write &quot;<td>Row2</td>&quot;
response.write &quot;</tr>&quot;
response.write &quot;</table>&quot;

%>
</body>
</html>



Andy
 
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>
<head>
<title>colors</title>
</head>

<body>

<table border=&quot;1&quot; >

<%
Dim iCount, strBGColor
iCount = 0

Do While Not objRS.EOF

If (iCount MOD 2 = 0) Then

strBGColor = &quot;#FFFFFF&quot;
Else
strBGColor = &quot;#DDDDDD&quot;
End If
%>

<tr bgcolor=&quot;<%= strBGColor %>&quot;><td>tetst</td></tr>

<%
iCount = iCount + 1
objRS.Movenext
Loop
%>
</table>
This would over come any problems with CSS that NETSCAPE 4.X might produce



</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top