User Guide

162 Chapter 9 Building Dynamic Forms
Reviewing the code
The following table describes the code and its function:
Code Description
<cfif isdefined
("Form.employee_grid.rowstatus.action")>
<cfloop index = "Counter" from = "1" to =
#arraylen(Form.employee_grid.rowstatus.action)#>
If there is an array of edit types, then the
table needs changing. Otherwise, do
nothing. Loop through the remaining code
once for each row to be changed. Counter
is the common index into the arrays of
change information for the row being
changed.
<cfoutput>
The row action for #Counter# is:
#Form.employee_grid.rowstatus.action[Counter]#
<br>
</cfoutput>
Display the action code for this row:
U, I, or D.
<cfif Form.employee_grid.rowstatus.action[counter]
is "D">
<cfquery name="DeleteExistingEmployee"
datasource="CompanyInfo">
DELETE FROM Employee
WHERE
Emp_ID=#Form.employee_grid.original
.Emp_ID[Counter]#
</cfquery>
If the action is to delete a row, generate a
SQL DELETE query specifying the
Emp_ID (the primary key) of the row to be
deleted.
<cfelseif Form.employee_grid.rowstatus.action
[counter] is "U">
<cfquery name="UpdateExistingEmployee"
datasource="CompanyInfo">
UPDATE Employee
SET LastName=
#Form.employee_grid.LastName[Counter]#,
Dept_ID=
#Form.employee_grid.Dept_ID[Counter]#
WHERE
Emp_ID=#Form.employee_grid.original.
Emp_ID[Counter]#
</cfquery>
Otherwise, if the action is to update a row,
generate a SQL UPDATE query to update
the LastName and Dept_ID fields for the
row specified by the Emp_ID primary table
key.