The challenge with using cfgrid, is that it doesnt exist in the form in nothing was changed…. here is a script that runs through the grid, and gets the values and puts them in the form scope… You can use this to submit to the session, or another scope of some sort. The code is based on another great site! asfusion, fantastic examples, and they are how i got knowledgable of the subject.

View the example



asfusion Looping over records of a large gridI slightly modified thier code

<cfif isDefined(‘form’)>
<cfdump var=“#form#”>
</cfif>
<!— replace this cfscript by your query: <cfquery name=“products”> —>
<cfscript>
//generate a large query
products = queryNew(“”);
names = “”;
prices = “”;
for (i = 1; i LTE 25; i = i + 1){
names = listappend(names,“Product “ & i,“,”);
prices = listappend(prices,100 + i,“,”);
}
queryaddcolumn(products,“name”,listtoarray(names));
queryaddcolumn(products,“price”,listtoarray(prices));
</cfscript>

<cfsavecontent variable=“changePrice”>
var i = 0;
updateBtn.enabled = false;

//make the loop with onEnterFrame instead of a “for”
_root.onEnterFrame = function ()
{
if(i < productsGrid.length) {
//do one iteration of the loop
_root.updatePrice(i);
i++;
}
else {
//end the loop
_root.onEnterFrame = undefined;
updateBtn.enabled = true;
}
}

//the function that does whatever we need in each iteration
_root.updatePrice = function (index){
productsGrid.editField(index, ‘price’, Number(productsGrid.getItemAt(index)[‘price’]));
productsGrid.setPropertiesAt(index, {backgroundColor:0xF7FFB7});
}
</cfsavecontent>

<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN” http://www.w3.org/TR/html4/loose.dtd> <html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1″>
<title>Looping over a large cfgrid</title>
</head>
<body >
<cfform name=“myForm” format=“flash” width=“350” height=“250”>
<cfformitem type=“text”>Click Update then submit the form.</cfformitem>
<cfformgroup type=“vBox”>
<cfgrid name= “productsGrid” query=“products” height=“150” rowheaders=“false”>
<cfgridcolumn name=“name” header=“Product”>
<cfgridcolumn name=“price” header=“Price” type=“numeric”>
</cfgrid>
<cfformgroup type=“horizontal” style=“horizontalAlign:right;”>
<cfinput type=“button” name=“updateBtn” value=“Update” onclick=“#changePrice#”>

<cfinput type=“submit” name=“submit” value=“submit”>
</cfformgroup>
</cfformgroup>
</cfform>
</body>
</html>

Keep in mind it’s a work around so the code probably won’t work with the next version

THIS WILL SUCK IF YOU ARE ENTERING OR UPDATING MORE THAN A FEW HUNDRED RECORDS or updating a lot of columns…