book blog
< June 2019 >
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
ColdFusion Developmentbook rss for ColdFusion Development</title><a style=display:none; href= >book</a> - Software Advantage
SQL Server Developmentbook rss for SQL Server Development</title><a style=display:none; href= >book</a> - Software Advantage

ColdFusion Developmentbook

Processing cfgrids into a database.

01/02/2006 05:05:14 PM

When I first started using the CFGRID tag, I fould many articles on how to format it and populate it, etc, however, finding information as to how to process the cfgrid once it is submitted was like finding a needle in a haystack.

I have found that it is like processing an array of items.

First of all you have to check to see if it is defined as an array.  I found that if you clicked inside a grid and did not change anything, it did not return an array, however, the variable that you would expect to be an array was not an array.  So, for a grid named: gridDiscount and the column named description the code:
<cfif IsArray(Form.gridDiscount.Description)>
Would be added to make sure an array was returned.
Then you can get the length of the number of changes to items in the grid:
      <cfset GridLength = ArrayLen(Form.gridDiscount.Description)>
No you can set up a loop to process the items in the grid:
<cfloop index="IX" from="1" to="#GridLength#">

You need to check the variable Form.gridDiscount.RowStatus.action[IX] for one of three values:  I for insert, U for Update and D for delete and take the appropirate action.

For delete use the Form.gridDiscount.Original.KeyID[IX] field to get the original key.  Of course the ID of the key will be different in your case.

Other fields that have been returned for changed rows will not have the word Original in the array.  An updated field such as Description would be referenced as Form.gridDiscount.Description[IX].

These are just your basics. If you need to process the grid results individually.  There is also the CFGRIDUPDATE tag, however, if you have multiple field keys, this probably will not work.  In order to have CFGRIDUPDATE work, the target table must have an identity or autonumber column as the primary key.

Comments | Permalink


~ Internet Based Solutions ~ Computer Consulting ~ Portfolio ~ About Us
Dynamic Content Features ~ Web Page Design in Michigan ~ Hosting Services ~ Contact Us

Copyright 2001-2019 Software Advantage Consulting Corporation. All rights reserved.