How to use cfswitch with cfcase in ColdFusion

cfswitch with cfcase

cfswitch.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfswitch tag example: how to use cfswitch tag with cfcase in coldfusion</title>
</head>

<body>
<h2 style="color:Crimson">cfswitch Tag Example</h2>

<cfquery name="qAuthor" datasource="cfbookclub">
    SELECT AuthorID, FirstName, LastName FROM AUTHORS
</cfquery>

<cfset Theme="Pink">
<cfswitch expression="#Theme#">
 <cfcase value="Pink">
  <cfset HeaderRowColor="Crimson">
        <cfset RegularRowColor="Pink">
        <cfset AlternetRowColor="HotPink">
    </cfcase>
 <cfcase value="Green">
  <cfset HeaderRowColor="Green">
        <cfset RegularRowColor="SeaGreen">
        <cfset AlternetRowColor="LightGreen">
    </cfcase>
    <cfdefaultcase>
  <cfset HeaderRowColor="White">
        <cfset RegularRowColor="White">
        <cfset AlternetRowColor="White">
    </cfdefaultcase>
</cfswitch>

<cfoutput>
    <table cellpadding="0" cellspacing="0">
        <tr bgcolor=#HeaderRowColor#>
            <td><b>AuthorID</b></td>
            <td><b>FirstName</b></td>
            <td><b>LastName</b></td>
        </tr>
        <cfloop query="qAuthor">
            <tr bgcolor=#IIF(qAuthor.CurrentRow mod 2 eq 0,DE(RegularRowColor),DE(AlternetRowColor))#>
                <td>#AuthorID#</td>
                <td>#FirstName#</td>
                <td>#LastName#</td>
            </tr>
        </cfloop>
    </table>
</cfoutput>

</body>
</html>





More ColdFusion examples