
740
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
<cfelseif Form.employee_grid.rowstatus.action[counter] is "I">
<cfquery name="InsertNewEmployee"
datasource="cfdocexamples">
INSERT into Employee (LastName, Dept_ID)
VALUES (<cfqueryparam
value="#Form.employee_grid.LastName[counter]#"
CFSQLType="CF_SQL_VARCHAR" >,
<cfqueryparam value="#Form.employee_grid.Dept_ID[counter]#"
CFSQLType="CF_SQL_INTEGER" >)
</cfquery>
</cfif>
</cfloop>
</cfif>
Click <a href="grid2.cfm">here</a> to display updated grid.
</body>
</html>
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, change 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.