Use CFGrid selectedItem as a form value

Can the selectedItem variable be refrenced in a form submission?  I am not sure if I am asking that right so here is an example:

OK, I have this grid in a form-->

<cfform action="anotherpage.cfm">
     <cfgrid name="Grid" query="Grid">
          <cfgridcolumn name="ColumnOne" header="Column One">
     </cfgrid>
</cfform>

Can it be refrenced in the submission of that form if a value is highlighted in that grid?

Example:
<cfquery datasource="Table">
     INSERT INTO tableOne (GridItemNumber)
     VALUES ('#Form.Grid.selectedItem.ColumnOne#')
</cfquery>

Again i am not sure if I am making sense to anyone.
myeritAsked:
Who is Participating?
 
8riaNCommented:
Yes, you can do this so long as you are not using CFGrid to edit the data.  If all the user needs to be able to do is select a cell, column, or row, this works fine.

The key change from your code is that you don't need selectedItem, and you have to set the SelectMode.

so lets say you want the click to select a row, and then reference column1 in that row, your code would look like this:
<cfform action="anotherpage.cfm">
     <cfgrid name="Grid" query="GridQuery" SelectMode="row">
          <cfgridcolumn name="ColumnOne" header="Column One">
          <cfgridcolumn name="ColumnTwo" header="Column Two">
          <!--- ... etc.  --->
     </cfgrid>
</cfform>

and in anotherpage.cfm ->
<cfquery datasource="Table">
     INSERT INTO tableOne (GridItemNumber)
     VALUES ('#Form.Grid.ColumnOne#')
</cfquery>
this will insert the value of ColumnOne in the query GridQuery (in the first .cfm file) for the row selected by the user on the cfgrid "Grid" into the column called GridItemNumber in the table tableOne

Which is what you want to do, right?

8riaN

Here's the relevent section from the help file:

If the SelectMode attribute equals Single, Column, or Row, the data returned by form variables to the cfform's ACTION page contains information about which cell or cells were selected by the user. In general, this data is made available by ColdFusion in the ACTION page as ColdFusion variables in the form scope using the following naming convention:

form.#GridName#.#ColumnName#.
Specifically, each SelectMode returns the following form variable(s):

SelectMode="single"
form.#GridName#.#ColumnName# = "SelectedCellValue"

SelectMode="column"
form.#GridName#.#ColumnName# = "ValueOfCellRow1, ValueOfCellRow2, ... ValueOfCellRowN"

SelectMode="row"
form.#GridName#.#Column1Name# ="ValueOfCellInSelectedRow"

form.#GridName#.#Column2Name# = "ValueOfCellInSelectedRow"

form.#GridName#.#ColumnNName# = "ValueOfCellInSelectedRow"

0
 
myeritAuthor Commented:
You are a genius!

Thanks much, that is exactly what I needed!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.