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

Not able to get the changed values in update command

3 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 05 Dec 2012, 07:11 AM
HI,
I am using the RAD Grid in sharepoint 2010.
I have the following code in the update command:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
  
            GridEditableItem editedItem = e.Item as GridEditableItem;
            DataTable ordersTable = this.GridData;
  
            //Locate the changed row in the DataSource
  
            string filter = "Title = '" + Convert.ToString(editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Title"]) + "'";
  
//  here Title='1' is shown. 1 is the value which is changed to 2.
  
            DataRow[] changedRows = ordersTable.Select(filter);
  
            if (changedRows.Length != 1)
            {
                RadGrid1.Controls.Add(new LiteralControl("Unable to locate the Order for updating."));
                e.Canceled = true;
                return;
            }
  
            //Update new values
            Hashtable newValues = new Hashtable();
            //The GridTableView will fill the values from all editable columns in the hash
// in the below code newvalues is coming as empty
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
  
            DataRow changedRow = changedRows[0];
            changedRow.BeginEdit();
            try
            {
                foreach (DictionaryEntry entry in newValues)
                {
                    changedRow[(string)entry.Key] = entry.Value;
                }
                changedRow.EndEdit();
            }
            catch (Exception ex)
            {
                changedRow.CancelEdit();
                RadGrid1.Controls.Add(new LiteralControl("Unable to update Orders. Reason: " + ex.Message));
                e.Canceled = true;
            }
            ordersTable.AcceptChanges();
              
            this.GridData = ordersTable;
            RadGrid1.DataBind();
        }

How to get the changed values?
Thanks

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 07 Dec 2012, 11:14 AM
Hello Venkatesh,

Thank you for contacting us.

Your update command is perfectly all right except for the last statement (RadGrid1.DataBind() ) which should be removed since the grid will rebind itself automatically upon the update command handler having been executed. In addition, do make sure that you are using Advanced data-binding for your grid as opposed to Simple data-binding.

If, however, this does not help, I'd ask you to send your complete implementation as a file attachment.

Regards, Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Venkatesh
Top achievements
Rank 1
answered on 09 Dec 2012, 06:38 AM
HI,
Thanks for the reply.
i have removed the databind last statement.
However, i am not getting the changed values. Below line is giving empty.
Hashtable newValues = new Hashtable();
            //The GridTableView will fill the values from all editable columns in the hash
// in the below code newvalues is coming as empty
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
0
Tsvetoslav
Telerik team
answered on 12 Dec 2012, 03:27 PM
Hello Venkatesh,

I understand but I need your complete code since the information provided is not sufficient to reveal the cause for the problem. It'd be even greater if you make it a runnable sample. Thanks for that.

Greetings, Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Venkatesh
Top achievements
Rank 1
Share this question
or