Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternating Colors on <TR> throughout a CFLOOP 1

Status
Not open for further replies.

rojas1mg

Programmer
Jun 15, 2004
119
US
Is there a way to alternate colors (say, bgcolor = white and bgcolor = lightgrey) inside a CFLOOP when outputting to a table? Thanks.


rojas1mg - - - I love Tek-Tips and all members who reply.
 
Disregard. I found it in my CFMX Web Application Contruction Kit (Fifth Edition) book.
Code:
<CFIF CurrentRow MOD 2 is 1>
  <CFSET bgcolor = "white">
<CFELSE>
  <CFSET bgcolor = "lightgrey">
</CFIF>

rojas1mg - - - I love Tek-Tips and all members who reply.
 
Forgot one important line of code:

Code:
[COLOR=brown]
<CFIF CurrentRow MOD 2 is 1>
  <CFSET bgcolor = [COLOR=blue]"white"[/color]>
<CFELSE>
  <CFSET bgcolor = [COLOR=blue]"lightgrey"[/color]>
</CFIF>[/color]
[COLOR=teal]<TR bgcolor=[COLOR=blue]"#bgcolor#"[/color]>[/color]

rojas1mg - - - I love Tek-Tips and all members who reply.
 
If it is a site where this could be duplicated over multiple pages that require different scripts, CSS could assist in easier updating for all at one time.

Code:
<CFIF CurrentRow MOD 2 is 1>
  <TR class="primaryrow">
<CFELSE>
  <TR class="secondaryrow">
</CFIF>

in style.css file:

primaryrow {
background:white;
}

secondaryrow {
background:lightgrey;
}

Style sheets make many things easier for updating site wide changes instantly.

xtendscott
Web Site Design and CF Programming
 
I do use CSS and was only using it for trial. Will update code to reflect the style sheet as it is FAR more powerful.

rojas1mg - - - I love Tek-Tips and all members who reply.
 
styles are cool.

however i find it's best if you assign the class to each cell. not the table row.

my example:
Code:
<td style = "<cfif currentrow mod 2 eq 0>evenRow<cfelse>oddRow</cfif>">

doing it by cell not row allows you to also check other things like negative values in the cell and assign a totally different class without having to worry about inhearatance(sp).



If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
I've added the suggested items to my style sheet as follows:

Code:
.[COLOR=purple]primaryrow[/color] [b]{[/b][COLOR=blue]background[/color]:[COLOR=red]lemochiffon[/color][b]}[/b]
.[COLOR=purple]secondaryrow[/color] [b]{[/b][COLOR=blue]background[/color]:[COLOR=red]white[/color][b]}[/b]

And my page as follows and it doesn't change anything. What am I doing wrong?

Code:
[COLOR=brown]<cfif billet.recordcount gt[/color] [COLOR=blue]0[/color]>
[COLOR=brown]<cfset allguests=[/color][COLOR=blue]""[/color]>
[COLOR=brown]<cfloop query=[/color][COLOR=blue]"billet"[/color][COLOR=brown]>
<cfset thisguest = guest_ID>[/color]
[COLOR=gray]<!---This determines the colors of the rows--->[/color]
[COLOR=brown]<CFIF CurrentRow MOD[/color] [COLOR=blue]2[/color] [COLOR=brown]is[/color] [COLOR=blue]1[/color]>
  [COLOR=teal]<TR class=[/color][COLOR=blue]"primaryrow"[/color][COLOR=brown]>[/color]
[COLOR=brown]<CFELSE>[/color]
  [COLOR=teal]<TR class=[/color][COLOR=blue]"secondaryrow"[/color][COLOR=brown]>
</CFIF>[/color]
[COLOR=gray]<!---<tr bgcolor="#bgcolor#">--->[/color]
	[COLOR=teal]<td align=[/color][COLOR=blue]"center"[/color][COLOR=teal]>[/color]#Guest_ID#[COLOR=teal]</td>[/color]
	[COLOR=teal]<td>[/color]#Rank#[COLOR=teal]</td>[/color]
	[COLOR=teal]<td>[/color]#Guest_First#[COLOR=teal]</td>[/color]
	[COLOR=teal]<td>[/color]#Guest_Last#[COLOR=teal]</td>[/color]
	[COLOR=teal]<td>[/color]#Email#[COLOR=teal]</td>[/color]

rojas1mg - - - I love Tek-Tips and all members who reply.
 
Want to know what my problem was? I mistyped "lemonchiffon". That's all it was. Sorry to trouble everyone. If you were in my office, you would've heard a loud "DOH!". Thank you.

rojas1mg - - - I love Tek-Tips and all members who reply.
 
instead of
.primaryrow {background:lemochiffon}

do
.primaryrow {background-color:#fffacd;}

OR

.primaryrow {background-color:lemonchiffon;}

spelling counts here.

 
Imstillatwork is probably more correct when using just a color for the background.

.primaryrow {background-color:lemonchiffon;}

If you want to have an image as the background or to cover a portion of the cell and a color as a backup if users have images turned off you can use the the following.

If you check for a negative value you could do something like this.

.negativeNumber {
color:red;
background: #FFFACD url(/images/smallRed-X.gif) no-repeat top left;
padding-left:10px; /* gives room for the X */
}


and r937, thanks.

xtendscott
Web Site Design and CF Programming
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top