Andy Matthews wrote:
>Or you could do it in one line with iif.
>
><cfset color = iif(somequery.CurrentRow mod 2,"000066","220088")>
>
>Also note that if you choose to use Matthew's way, which works just fine
>too, it's not necessary to pound the somequery.CurrentRow variable.
>
It never ceases to amaze me that many developers strive for code reuse
and modularization and separating business logic from presentational
code but rarely seem to apply the same principles to their HTML coding ;-)
Regardless of the CF syntax used (iff / <cfif>), here's a more efficient
way to code this functionality:
The following CSS code should be put in an external style sheet:
..evenRow {
background-color: #ccc;
}
..oddRow {
background-color: #fff;
}
Then in the cfm template:
<cfset rowClass = "oddRow">
<table>
<cfoutput query="someQuery">
<cfif someQuery.CurrentRow mod 2>
<cfset rowClass = "oddRow">
<cfelse>
<cfset rowClass = "evenRow">
</cfif>
<tr class="#rowClass#">
<td>#someQuery.CurrentRow#</td>
<td>some data</td>
</tr>
</cfoutput>
</table>
This way the actual colors used are not hardwired in the template and
can be changed from the CSS file and the HTML markup is separate from
the presentation.
Cheers!
Stéphane Bergeron
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220246
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54