Internet.comReal World Active Server Pages Solutions and Resources 
ASPWatch.com
Sponsored by Compuware Corporation
Essential survival skills for Internet success!
ScriptingDatabaseComponentsXMLIntegrationSolutions

Newsletter
Click here!
Search


Pete Nelson's Home Page
Log off

internet.com
Internet News
Internet Investing
Internet Technology
Windows Internet Tech.
Linux/Open Source
Web Developer
ECommerce/Marketing
ISP Resources
ASP Resources
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers


Register Domains
Affiliate Solutions
Find a Consultant
Buy BSD Products
Web System Integrator
Training Solutions
Document Management
Search Engine Experts
Add Online Sales Reps
Outsource IT Work

How-To: Color Banding
by Pete Nelson
Skill level: Beginner
First posted: Tuesday, May 09, 2000
Overview

Color banding is the simple technique of alternating the background color of each line in a table to make the output more readable. Notice how we alternate between white and grey in the image below.

Figure
(Example of Color Banding)


This is extremely usefull when displaying large amounts of data that all looks similar, such as sequential dates and numbers.


The Code

The concept behind this is pretty basic, and so is the code. In whatever loop you're running (recordset, For..Next, etc), we use a variable to keep track of how many rows we have displayed. By determining if the current row number is odd or even, we know which color to display. Use the Mod statement and divide a number by two. If it returns zero, it's even, otherwise it's odd. In the example below, we select several records from a table, and as we display them, we alternate the background color between white and grey.

<table>
   <tr>
   <td>SessionID</td>
   <td>DateStart</td>
   </tr>

<%
'*** conDB is an already defined connection object
Dim recSession, intX, strBGColor
Set recSessions = conDB.Execute("Select * from Sessions")

'*** Start with an odd number to display white
intX = 1

do while not recSessions.EOF

   if intX Mod 2 = 0 then '*** Even, display Grey
      strBGColor = "EEEEEE"
   else '*** Odd, display white
      strBGColor = "FFFFFF"
   end if

   %>
   <tr bgcolor="#<% =strBGColor %>">
   <td><% =recSessions("SessionID") %></td>
   <td><% =recSessions("DateStart") %></td>
   </tr>
   <%

   intX = intX + 1 '*** Increment the row counter

   recSessions.MoveNext
loop

recSessions.Close
Set recSessions = Nothing
%>
</table>



With the addition of some simple code, you can make your reports look very sharp and professional!






Pete Nelson
Pete is the webmaster for DVD Tracker, a site that lets people keep an online catalog of their DVD collection. He has been doing ASP development for three years and is proficient in VBScript, SQL and HTML, and dabbles in VB COM, PHP and mySql now and then. He's married to a Linux geek and lives in the San Francisco Bay Area.
What did you think of this article?
Not usefulVery useful
Badly writtenWell written
Too short Too long
This document can be found in these Encyclopedia chapters:
º Tricks of the Trade
This is what people have been saying about this article:
More Efficient Method - Anonymous - Tuesday May 9 6:44:00 PM
   More Efficient Method - Anonymous - Tuesday May 9 6:44:00 PM
Make your rows look whole - Anonymous - Tuesday May 9 6:51:00 PM

Create a new discussion
View Article Statistics

Authors...
Edit this article
View Preview Version
Printable Copy of Article
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

About your privacy | Want to advertise? | Contact Us

Copyright © internet.com Corporation 2001
http://www.internet.com