User Guide

Table Of Contents
654 Chapter 27: Building Dynamic Forms with cfform Tags
2.
Rename your existing handle_grid.cfm file as handle_grid2.cfm to save it, and then save this file
as handle_grid.cfm.
3.
View the grid2.cfm page in your browser, make changes to the grid, and then submit them.
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, changes
the table. Otherwise, does nothing.
Loops through the remaining code once
for each row to be changed. The
counter
variable 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>
Displays the action code for this row:
U for update, I for insert, or D for delete.
<cfif Form.employee_grid.rowstatus.action[counter]
is "D">
<cfquery name="DeleteExistingEmployee"
datasource="cfdocexamples">
DELETE FROM Employee
WHERE Emp_ID=<cfqueryparam
value="#Form.employee_grid.original.Emp_ID
[counter]#"
CFSQLType="CF_SQL_INTEGER" >
</cfquery>
If the action is to delete a row, generates
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="cfdocexamples">
UPDATE Employee
SET LastName=<cfqueryparam
value="#Form.employee_grid.LastName[counter]#"
CFSQLType="CF_SQL_VARCHAR" >,
Dept_ID=<cfqueryparam
value="#Form.employee_grid.Dept_ID[counter]#"
CFSQLType="CF_SQL_INTEGER" >
WHERE Emp_ID=<cfqueryparam
value="#Form.employee_grid.original.Emp_ID
[counter]#"
CFSQLType="CF_SQL_INTEGER">
</cfquery>
Otherwise, if the action is to update a
row, generates a SQL UPDATE query to
update the LastName and Dept_ID
fields for the row specified by the
Emp_ID primary table key.