Creating alternating rows in ColdFusion

02 September 2011

One of those things that could be very complex or very easy is creating zebra-striped alternating rows in a table or list. In ColdFusion this is quite easy to achieve. No counters and lengthy if-statements, just one small line of code!

<table>
<cfoutput query="queryVar">
    <tr class="<cfif currentrow mod 2>odd<cfelse>even</cfif>_row">
        <td>Column 1</td>
        <td>Column 2</td>
        <td>Column 3</td>
    </tr>
</cfoutput>
</table>

And the CSS:

.even_row td {
    background-color: #F2F2F2;
}
.odd_row td {
    background-color: #FFFFFF;
}

That's all!
You must have JavaScript enabled to use this form!

Leave a comment!

  1. Your mail is safe with me. It's only only used to display your Gravatar image!

1 comment

  1. Gravatar

    Antonio

    25 April 2014

    Thanks for the code