User Guide

314 Chapter 2: ColdFusion Tags
Example
<!--- This example shows the use of cftree, cfselect and cfgrid in a cfform.
The query takes a list of employees, and uses cftree and cfselect to
display results of query. cfgrid is used to show an alternate means
of displaying the data --->
<!--- set a default for the employeeNames variable --->
<cfparam name = "employeeNames" default = "">
<!--- if an employee name has been passed from the form, set employeeNames
variable to this value --->
<cfif IsDefined("form.employeeNames") is not "False">
<cfset employeeNames = form.employeeNames>
</cfif>
<!--- query the datasource to find the employee information--->
<cfquery name = "GetEmployees" dataSource = "cfsnippets">
SELECT Emp_ID, FirstName, LastName, EMail, Phone, Department
FROM Employees
WHERE 0=0
<cfif employeeNames is not "">
AND LastName = '#employeeNames#'
</cfif>
</cfquery>
<h3>cfselect Example</h3>
<!--- Use cfform when using other cfinput tools --->
<cfform action = "cfselect.cfm">
<!--- Use cfselect to present the contents of the query by column --->
<h3>cfselect Presentation of Data</h3>
<h4>Click on an employee’s last name and hit "see information for this
employee"
to see expanded information.</h4>
<cfselect name = "EmployeeNames"
message = "Select an Employee Name"
size = "#getEmployees.recordcount#"
query = "GetEmployees" value = "LastName"
required = "No">
<option value = "">Select All
</cfselect>
<input type="Submit"
name="" value="see information for this employee">
<!--- showing the use of cftree ------------------------------------------>
<!--- use cftree for an expanded presentation of the data Loop through the
query to create each branch of the CFTREE ----------------------------->
<h3>cftree Presentation of Data</h3>
<h4>Click on the folders to "drill down" and reveal information.</h4> <p>
<cftree name="SeeEmployees"
height="150" width="240" font="Arial Narrow" bold="No"
italic="No" border="Yes" hscroll="Yes" vscroll="Yes"
required="No" completepath="No" appendkey="Yes" highlighthref="Yes">
<cfloop query="GetEmployees">
<cftreeitem value="#Emp_ID#" parent="SeeEmployees" expand="No">
<cftreeitem value="#LastName#" display="Name" parent="#Emp_ID#"
queryasroot="No" expand="No">
<cftreeitem value="#LastName#, #FirstName#" parent="#LastName#"
expand="No" queryasroot="No">
<cftreeitem value="#Department#" display="Department" parent="#Emp_ID#"
queryasroot="No" expand="No">
<cftreeitem value="#Department#" parent="#Department#"