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

alternating row color

Status
Not open for further replies.

mcpeekj

Vendor
Sep 21, 2001
105
hi all. thanks for all the help to date. all of my functionality is done and working smoothly. now i have a cosmetic question. i want to alternate row colors for my listing page. i've found a handful of code snippets on the web, but haven't been able to get anything to work. here's what is closest:
<TABLE border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;400&quot;>
<%
Dim Row, intRow
intRow = 0
For intRow = 1 To rs.RecordCount
if (Row = 2) Then
response.write(&quot;<TR bgcolor=white >&quot;)
Row = 1
Else
Row = 2
response.write(&quot;<TR bgcolor=Silver>&quot;)
End if
%>
<TD class=&quot;tblContent&quot;><%= intRow %>
</TD>
</TR>
<%
Next
%>
</TABLE>


with this code, it writes each row number, one after the other. it doesn't actually bring anything out of my db. so, if you would please, tell me how to get this code to do something relevant, or point me in the direction of some better code...
 
<%

x=1 'row color counter intialized
do while not rs.eof
if x = 1 then
response.write &quot;<tr bgcolor=&quot;white&quot;>&quot;
x=2
else
response.write &quot;<tr bgcolor=&quot;silver&quot;>&quot;
x=1
end if
'put all the DB data here other than titles for the columns
response.write &quot;<td>&quot; & rs(&quot;somefield&quot;) & &quot;</td><td>&quot; & rs(&quot;anotherfield&quot;)</td>&quot;
response.write &quot;</tr>&quot;
loop

%>

hth Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
mcpeekj,
' I is the row number
If (I mod 2) = 1 then
Response.Write &quot;<TR BGCOLOR=&quot;&quot;#B0B0B0&quot;&quot;>&quot;
Else
Response.Write &quot;<TR BGCOLOR=&quot;&quot;#FFFFFF&quot;&quot;>&quot;
End IF

fengshui_1998
 
just another alternative that saves you one variable and some space

for intRow = 1 to rs.recordcount
if (intRow mod 2) = 0 then
response.write(&quot;<TR bgcolor=white>&quot;)
else
response.write(&quot;<TR bgcolor=silver>&quot;)
end if
next
 
<%
Dim Color(2)

SelectColor = 1

Color(1) = &quot;<TR bgcolor=white>&quot;
Color(2) = &quot;<TR bgcolor=silver>&quot;

For intRow = 1 To rs.RecordCount
Response.Write(Color(SelectColor))

If SelectColor = 1 then SelectColor = 2 Else SelectColor = 1

%>


www.vzio.com
ASP WEB DEVELOPMENT



 
try this.
i presume you have already populated data in your recordset using a query.

---------------------------------------------------------
<TABLE border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;400&quot;>
<tr bgcolor='#ffffdd'><td>No.</td><td>Name</td><td>Address</td></tr>

<%
Dim intRow
intRow = 0

do while not rs.eof
if (intRow mod 2) = 0 then
response.write(&quot;<TR bgcolor=white>&quot;)
intRow = 1
else
response.write(&quot;<TR bgcolor=silver>&quot;)
intRow = 0
end if

%>
<TD><%= rs.AbsolutePosition %></TD>
<td><%= rs(&quot;Name&quot;)%> </td>
<td><%= rs(&quot;Address&quot;)%> </td>
</TR>
<%
rs.MoveNext
loop
%>

</TABLE>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top