User Guide

Chapter 10: Building Dynamic Forms 137
Code Review
Note If you specify a CFGRID tag with a QUERY attribute defined and no
corresponding CFGRIDITEM attributes the default grid that is created
contains all the columns in the query.
Creating an Updateable Grid
You can build grids to allow users to edit data within them. Users can edit individual
cell data, as well as insert, update, or delete rows. To enable grid editing, you specify
SELECTMODE="EDIT" in the CFGRID tag and enable the INSERT or DELETE
attributes in CFGRID.
You can then use either of two ways to use an updateable grid to make changes to your
ColdFusion data sources.
Create a page to which you pass the CFGRID form variables and in that page
perform CFQUERY operations to update data source records.
Pass grid edits to a page that includes the CFGRIDUPDATE tag, which passes
data directly to the data source.
Although using CFQUERY gives you complete control over interactions with your data
source, CFGRIDUPDATE provides a much simpler interface for operations that do not
require the same level of control.
Code Description
<CFGRID NAME="employee_grid"
QUERY="empdata"
Create a grid named "employee_grid"
and popluate it with the results of the
query "empdata"
SELECTMODE="single">
Allow the user to select only one cell.
<CFGRIDCOLUMN NAME="Employee_ID">
Put the contents of the Employee_ID
column in the query results in the first
column of the grid
<CFGRIDCOLUMN NAME="LastName">
Put the contents of the LastName
column in the query results in the
second column of the grid
<CFGRIDCOLUMN NAME="Department_ID">
Put the contents of the
Department_ID column in the query
results in the third column of the grid