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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternating row colors 2

Status
Not open for further replies.

KevinFSI

Programmer
Nov 17, 2000
582
US
I used to know the code for alternating row colors on tables that were created dynamically. Can someone out there help jar my memory please? Kevin
slanek@ssd.fsi.com
 
Nevermind. I found some old code.

If anyone out there wants the answer, this is how I did it before.

Code:
<CFIF queryname.currentrow MOD 2 IS
0>bgcolor=&quot;mycolor&quot;<CFELSE>
bgcolor=&quot;anothercolor&quot;</CFIF>
Kevin
slanek@ssd.fsi.com
 
Just to rewrite the code for non query related loops.

<cfset loopCount = 0>
<cfloop {looping condition}>
<cfif loopCount MOD 2 IS 0>
<cfset myColor = &quot;red&quot;>
<cfelse>
<cfset myColor = &quot;ff66ff&quot;>
</cfif>
...code <table bgcolor=&quot;#myColor#&quot;> ...
<cfset loopCount = loopCount + 1>
</cfloop>

note that if the loop is indexed then the name of the index
can be used instead of creating the variable loopCount
 
You can use this code also

<table>
<cfoutput query=&quot;myQuery&quot;>
<tr bgcolor=&quot;###Iif(((CurrentRow MOD 2) is 0),de('ff3060'),de('ff0000'))#&quot;>
<td>#Field1#</td>
<td>#Field2#</td>
</tr>
</cfoutput>
</table>

By(e)
micjohnson
 
this is just for not using MOD and it's simple.

<cfset bgcolor=&quot;oneColor&quot;>
<cfloop query=&quot;query&quot;>
<cfif bgcolor is &quot;oneColor&quot;>
<cfset bgcolor = &quot;anotherColor&quot;>
<cfelse>
<cfset bgcolor = &quot;oneColor&quot;>
</cfif>
</cfloop>
 
Hi,

Does anyone know how to do this within the confines of a <cftable> tag? <cftable> doesn't allow any bgcolor attributes. Following is my code, and every row just defaults to white.


<table width=800 border=1>
<tr>
<cfset #rowcolor# = 'white'>
<td bgcolor=&quot;<cfoutput>#rowcolor#</cfoutput>&quot;>
<CFTABLE Query=&quot;achdata&quot; HTMLTABLE BORDER COLHEADERS MAXROWS=200>
<CFCOL Header=&quot;<B>Branch Code</B>&quot; Width=8 Text=&quot;#wach_branch_code#&quot;>
<CFCOL Header=&quot;<B>Agent Code</B>&quot; Width=8 Text=&quot;#wach_agent_code#&quot;>
<CFCOL Header=&quot;<B>Ins Last Name</B>&quot; Width=20 Align=Right Text=&quot;#wach_ins_last_name#&quot;>
<CFCOL Header=&quot;<B>Ins First Name</B>&quot; Width=10 Align=Right Text=&quot;#wach_ins_first_name#&quot;>
<CFCOL Header=&quot;<B>M.I.</B>&quot; Width=5 Align=Right Text=&quot;#wach_ins_middle_initial#&quot;>
<CFCOL Header=&quot;<B>Tran Date</B>&quot; Width=10 Align=Right Text=&quot;#wach_tran_date#&quot;>
<CFCOL Header=&quot;<B>Binder Number</B>&quot; Width=15 Align=Right Text=&quot;#wach_binder_number#&quot;>
<CFCOL Header=&quot;<B>Bank Account Number</B>&quot; Width=17 Align=Right Text=&quot;#wach_bank_account_num#&quot;>
<CFCOL Header=&quot;<B>Bank Amount</B>&quot; Width=10 Align=Right Text=&quot;#wach_bank_amount#&quot;>
</CFTABLE>
<cfif (#achdata.currentrow# mod 2) eq 0>
<cfset #rowcolor# = 'white'>
<cfelse>
<cfset #rowcolor# = 'blue'>
</cfif>
</td>
</tr>
</table>



Thanks in advance,
scripter73
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top