ColdFusion Tutorial

Alternate table rows color

One of the most frequently asked questions is how to alternate the row colors for dynamically generated HTML tables. There are several ways to do this, the easiest is to use the IIF() and DE() functions as shown in the following example:

Example:

<table border="1" cellpadding="0" cellspacing="0" width="100%">

<TR BGCOLOR="#888888">
   <TH>Name</TH>
</TR>   

<CFOUTPUT QUERY="your_query">
<TR BGCOLOR="###IIF(your_query.currentrow MOD 2, DE('E6E6E6'), DE('C0C0C0'))#">
   <TD>#Name#</TD>
</TR>   
</CFOUTPUT>
</TABLE> 


Name

Peter
Paul
Mary
And you

The row color alternates by using the IIF() and DE() functions along with the MOD operator to determine whether or not the row number for the current record being outputted is odd or even. Depending on the outcome of the evaluation, one color or the other is used as the background color for the current row. Though hex color codes are supposed to begin with a hashmark (#), we have to create an escape sequence before the IIF() function is called. This is done by a double hashmark in front of the first.

Here is a tutorial doing this in CSS.

ColdFusion Tutorial test

Alternate table rows color

No test is available or implemented for this ColdFusion Tutorial.

No User Comments.

No User Comments, be the first one to write your comments?

Add your comments

Your Name*:
Your Email:
Site URL:
Site Name:
Comemt Title*:
Your Comment*:
Key Phrase*:
iH6
Your IP Address: 38.103.63.62
 

ScandicWeb is own by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.