Home / Products / UltraDev / Support / Adding Dynamic Content
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Customizing Dreamweaver UltraDev
Writing the ColdFusion code

To make colors alternate in a repeated region, you need to control the color attribute inside the tag that is repeated—typically an HTML row tag (<tr> ) or an HTML table tag (<table> ). For simplicity, the article assumes you applied the repeated region to a table row. Except for the HTML tag used, the information is the same for HTML tables.

The color attribute of the <tr> tag is bgcolor —for example, <tr bgcolor="yellow"> . Your code must tell the application server to insert the bgcolor attribute in the <tr> tag every other time the tag is repeated.

Switch to Code view (View > Code) and find the first <tr> tag after the start of the repeat region server behavior. To help you recognize the server behavior in the code, here's how UltraDev 4 starts a ColdFusion repeated region:

<cfoutput query="myRecordset" startrow=#Repeat1_StartRow# maxrows=#Repeat1_NumRows#> 
Next, enter the following conditional expression inside the <tr> tag:
	<cfif (currentrow MOD 2) IS 1> bgcolor="silver" </cfif>
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>

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 value—here, 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.

To Table of Contents Back to Previous document Forward to next document