|
|
| Databases 101 | | | ASP.NET Chapter | | | Suggest Article | | | Discussions | | | Bookstore | | | Write for Us | | | OpenAuction | | | Our Authors | |
|
|
|
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.
 (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!
|
| |  | |  |
This document can be found in these Encyclopedia chapters: º Tricks of the Trade
|
 |
|
 |
This is what people have been saying about this article:
Create a new discussion |
 |
|
 |
View Article Statistics
Authors... Edit this article View Preview Version
|
|
| Printable Copy of Article |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
|