This is a migrated thread and some comments may be shown as answers.

Data from autogenerated edit form is SavedOldValues

4 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 15 Jul 2010, 05:30 PM
Hello,

I have an autogenerated edit form, I'm trying to get the data from the controls on the edit form as follows, but the data in the controls is the un-editted value. This is how all the examples show this working. Any ideas?

Thanks!

#region gvLUs_UpdateCommand event
    protected void gvLUs_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        //Get the GridEditableItem of the RadGrid     
        GridEditableItem editedItem = e.Item as GridEditableItem;
  
        // Build our Update string
        string strUpdate = "";
        string strWhere = "";
  
        int ic = 0;
        GridColumn editColumn;
  
        for (int i=0; i<gvLUs.MasterTableView.AutoGeneratedColumns.Count(); i++)
        {
            ic++;
  
            if (i == 0)
            {
                // Get our PK column
                editColumn = gvLUs.MasterTableView.AutoGeneratedColumns[i];
                LU.ID = editColumn.UniqueName.ToString();
                LU.IDValue = Convert.ToInt32((editedItem[editColumn].Controls[0] as TextBox).Text);
                // Add to our UPDATE string
                strUpdate = "UPDATE " + LU.TableName + " SET ";
                strWhere = " WHERE " + LU.ID + " = " + LU.IDValue.ToString();
            }
            else
            {
                if (ic != gvLUs.MasterTableView.AutoGeneratedColumns.Count())
                {
                    // Get other values to be updated
                    editColumn = gvLUs.MasterTableView.AutoGeneratedColumns[i];
                    strUpdate += editColumn.UniqueName.ToString() + " = '" + (editedItem[editColumn.UniqueName].Controls[0] as TextBox).Text + "' ,";
                }
                else
                {
                    // Get other values to be updated
                    editColumn = gvLUs.MasterTableView.AutoGeneratedColumns[i];
                    strUpdate += editColumn.UniqueName.ToString() + " = '" + (editedItem[editColumn.UniqueName].Controls[0] as TextBox).Text + "'";
                }
            }
  
        }

4 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 16 Jul 2010, 09:24 AM
Hi Brad,

Just use the ExtractValues method of the GridEditableItem object passing to it a hash table. The latter will be populated with all the column fields key-value pairs:

protected void gvLUs_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        //Get the GridEditableItem of the RadGrid      
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        Hashtable newValues = new Hashtable();
        editedItem.ExtractValues(newValues);
        ...
        ...
        ...
}

Hope it helps.

All the best,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Brad
Top achievements
Rank 1
answered on 16 Jul 2010, 01:18 PM
Thanks for the reply, the values came back into the hash table as still the original, un-editted values. Is this possibly a version bug?

I have the same problem when trying to Insert new records. The values all come in as empty strings.

Could it matter that I'm populating off of a DataTable?

Help!
0
Brad
Top achievements
Rank 1
answered on 17 Jul 2010, 12:54 AM
The only difference I see between this grid and the 2 working ones from the same project is that the autogenerated grid does not have a datakey.

Is this a possibility?

Thanks!

EDIT - Apparently not, I was able to add the DataKeyName and still could not extract any values.
0
Brad
Top achievements
Rank 1
answered on 17 Jul 2010, 03:56 AM
Well I seem to have figured it out. When using an autogenerated edit form it seems you need to use OnNeedData event to populate your rad grid. It seems like a very useful convience function, one I wasn't using in my other 2 implementations and will probably go back now and adjust that.

My guess is I was overwriting my editted values with original values somehow in my logic chain. All seems to be well now.

Hopefully this mess of a thread will help another newbie :)
Tags
Grid
Asked by
Brad
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Brad
Top achievements
Rank 1
Share this question
or