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

how to save results of batch editing, all rows, all cells

8 Answers 652 Views
Grid
This is a migrated thread and some comments may be shown as answers.
StringTheory
Top achievements
Rank 1
StringTheory asked on 07 Apr 2014, 06:26 PM
Hi,
In reading the documentation here:

http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html

I see this:
 CautionWhen setting the EditMode to Batch multi-row editing is not supported as only one editor is initialized for a given column(for performance purposes).

This caution would seem to defeat the purpose of batch (Excel-like) editing.

I'm trying to find a way to save the new values for all rows and all cells that have the red triangle on them as the result of batch editing. As it is now, I can only retrieve the values from the cell that is currently having an edit made. 

Here is the start of my code. Perhaps it's not firing on the proper event.

Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
 
    Dim argument As Telerik.Web.UI.GridBatchEditingEventArgument = TryCast(e.CommandArgument, Telerik.Web.UI.GridBatchEditingEventArgument)
    Dim oldValues As Hashtable = argument.OldValues
    Dim newValues As Hashtable = argument.NewValues

Thanks in advance.

8 Answers, 1 is accepted

Sort by
0
StringTheory
Top achievements
Rank 1
answered on 07 Apr 2014, 09:12 PM
update: I can now iterate through all the rows that have gotten updated, but am still struggling to figure out which field in the row was updated. According to numerous posts by Telerik staff, the standard way to retrieve oldValues is as noted above (Dim oldValues as hashtable=argument.OldValues). However, I cannot retrieve anything from oldValues. 

I can see the new values via newValues("theField").toString.

I cannot see oldValues via a similar call: oldValues("theField").toString

 FYI this is the starting portion of the function which iterates through the changed rows. 
Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridBatchEditingEventArgs)    
For Each command As Telerik.Web.UI.GridBatchEditingCommand In e.Commands
         If command.Type = Telerik.Web.UI.GridBatchEditingCommandType.Update Then
             Dim oldValues As Hashtable = command.OldValues
             Dim newValues As Hashtable = command.NewValues
...

One other note for Telerik dev's: Let me know if I should post this as a bug, but if I am in batch edit mode, and simply click my mouse in a dropdown list in a row, but don't change it, and click Update, then that row gets added to the hashtable.
0
Viktor Tachev
Telerik team
answered on 10 Apr 2014, 01:10 PM
Hi,

When using Batch editing mode for RadGrid the ItemCommand, UpdateCommand, DeleteCommand, InsertCommand are fired multiple times for every change made on the client. If you would like to access the value in given column for the currently updated item you could use the column UniqueName.

For your convenience I have prepared a sample project with Batch editing mode in RadGrid where Update and Insert commands are implemented. Try using similar approach for updating values with Batch editing.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Snehal
Top achievements
Rank 1
answered on 07 Nov 2014, 06:08 AM
Hi ,
   I am facing save issue . still not able to update records to database.
   I guess    Hashtable oldValues = command.OldValues;  maintains values of only for GridBoundColumn not   for GridTemplateColumn ,because  I am  also not getting all the grid column in OLDVALUES collection.
please correct me if i am wrong .

   I tried the solution attached (RadGridBatchEditingSample.zip)  at my end,  but still no luck .
    First of all "RadGrid1_UpdateCommand " event is not getting fired .Only the event which is fired is      "RadGrid1_BatchEditCommand"   and in RadGrid1_BatchEditCommand   event     i tried following code  
          GridEditableItem editedItem = e.Item as GridEditableItem;
          DataSet newData = FillView(); //  this return dataset which is bind to grid 
          DataRow[] data = newData.Tables[0].Select("RequestID = " +              editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["RequestID"].ToString());

   Its returning me null , even though cell are marked in red color .

      I also tried to read the  values  directly  by UniqueName   ..  but hard luck . struggling with same problem from last 2 days
  kindly assist.















0
Viktor Tachev
Telerik team
answered on 11 Nov 2014, 01:56 PM
Hi Snehal,

The behavior you describe seems strange. I tried to replicate the issue, however, I was unable to. I modified the previous sample so that one of the columns is GridTemplateColumn. Still, the data is updated as expected on my end.

Give the attached sample a try and let me know how it works for you.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Supachai
Top achievements
Rank 1
answered on 23 May 2015, 09:57 AM

Hi Viktor,

I followed your RadGridBatchEditingSample.zip. It is working when I use "save changes" from default command button. But it does not work when I click update button from CommandItemTemplate. Could you advice me how to make the same behavior in your sample work with button in CommandItemTemplate.

 Regards,

Supachai.

0
Supachai
Top achievements
Rank 1
answered on 23 May 2015, 10:07 AM
For more information about my problem. When I click update button from CommandItemTemplate. I got "Unable to cast object of type 'System.String' to type 'Telerik.Web.UI.GridBatchEditingEventArgument'" on UpdateCommand event handler.
0
Viktor Tachev
Telerik team
answered on 26 May 2015, 11:41 AM
Hello Supachai,

In order to save the changes in RadGrid with a Button control that us different than the default one you should use the following approach.

Handle the OnClientClick event of the Button and call the client-side saveChanges() method for the GridTableView.

The following code snippets illustrate the approach.

CommandItemTemplate markup:

<CommandItemTemplate>
    <asp:Button Text="Save Changes" runat="server" OnClientClick="saveChanges(this, event); return false;" />
</CommandItemTemplate>

JavaScript handler:

function saveChanges(sender, args) {
    var grid = $find("<%= RadGrid1.ClientID %>");
    var masterTableView = grid.get_masterTableView();
    var batchEditingManager = grid.get_batchEditingManager();
 
    batchEditingManager.saveChanges(masterTableView);
}


In addition I am attaching the sample project with applied modifications.


Regards,
Viktor Tachev
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Supachai
Top achievements
Rank 1
answered on 27 May 2015, 03:27 PM
Thank you Viktor. This is what I really want to know.
Tags
Grid
Asked by
StringTheory
Top achievements
Rank 1
Answers by
StringTheory
Top achievements
Rank 1
Viktor Tachev
Telerik team
Snehal
Top achievements
Rank 1
Supachai
Top achievements
Rank 1
Share this question
or