Use CFGrid selectedItem as a form value

Posted on 2005-04-28
Last Modified: 2013-12-24
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">

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

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

Again i am not sure if I am making sense to anyone.
Question by:myerit
    LVL 5

    Accepted Solution

    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.  --->

    and in anotherpage.cfm ->
    <cfquery datasource="Table">
         INSERT INTO tableOne (GridItemNumber)
         VALUES ('#Form.Grid.ColumnOne#')
    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?


    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:

    Specifically, each SelectMode returns the following form variable(s):

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

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

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

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

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


    Author Comment

    You are a genius!

    Thanks much, that is exactly what I needed!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
    Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now