|
In the above code, currentrow is a ColdFusion variable that returns the current row's position in the recordset. The expression (currentrow MOD 2) reads the number of the current row in the recordset, divides it by 2, and returns the remainder. If the remainder is equal to 1 (that is, if the row number is an odd number), then the application server inserts the string bgcolor="silver" inside the <tr> tag. Otherwise, it does nothing.
The previous code creates a repeated region with a single added color: the application server inserts a bgcolor attribute in one <tr> tag, leaves out the bgcolor attribute in the following <tr> tag, and so on. To create a repeated region with two alternating colors instead of one, enter the following code:
<tr bgcolor=
<cfif (currentrow MOD 2) IS 1>
"silver"
<cfelse>
"##FFCC66"
</cfif>
>
In this code, the attribute's name is hard-coded in the HTML (<tr bgcolor= ), meaning each row gets the attribute. The application server supplies the attribute's valuehere, silver or #FFCC66, a shade of orange.
Note: Because the # character serves a special purpose in ColdFusion, you need an extra # character in the color code to "escape" the character.
|