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

Problems with RadGrid1_UpdateCommand in batch edit mode

5 Answers 241 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ralph
Top achievements
Rank 1
Ralph asked on 20 Feb 2014, 07:51 PM
Hi,

I have a radgrid based on a view (two tables) using entity datasource. 
When MasterTableView has EditMode="Batch" I am trying to use RadGrid1_UpdateCommand to
update values

 

Protected Sub RadGrid1_UpdateCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand

        Dim editableItem = (DirectCast(e.Item,GridEditableItem))

        Dim partId = DirectCast(editableItem.GetDataKeyValue("PartID"), String)

        Dim coeus As New RTClientEntities()

        Dim part = coeus.Parts.Where(Function(p) p.PartID = partId).FirstOrDefault()

        If part IsNot Nothing Then

                      editableItem.UpdateValues(part)
          
                      part.LastChangedBy = getUser()

                     coeus.SaveChanges()
      End If

 
End Sub

 

 

When this function executes, editableItem has old values and updates part with them.

I can see new values in
TryCast(e.CommandArgument, GridBatchEditingEventArgument).NewValues()

When I change EditMode="InPlace" , everything works just fine.

Is there something I can do to new values in batch edit mode?  

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Feb 2014, 03:41 AM
Hi Ralph,

You can use the OnBatchEditCommand event of the RadGrid to perform update operations. Please take a look at the below code snippet.

C#:
protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
  foreach (GridBatchEditingCommand command in e.Commands)
  {
    if (command.Type == GridBatchEditingCommandType.Update)
     {
      Hashtable newValues = command.NewValues;
      Hashtable oldValues = command.OldValues;
      string ID = newValues["ID"].ToString();
      //Code to Update
     }
  }
}

Thanks,
Princy
0
Ralph
Top achievements
Rank 1
answered on 21 Feb 2014, 02:55 PM
Hi,

Problem I'm having is that e.Item contains old values.  When I perform editableItem.UpdateValues(part)
part gets populated with old values, instead of new values.

Is there a way to save new values without manually assigning them to me entity object for new value hash table?

0
Princy
Top achievements
Rank 2
answered on 24 Feb 2014, 03:11 AM
Hi Ralph,

When RadGrid performs CRUD operations ItemCommand, InsertCommand, DeleteCommand, UpdateCommand events are fired. To continue this trend when batch editing is enabled the events will be called multiple times for each operation made on the client. The event argument passed to the event handler will be of type GridBatchEditingEventArgument which contains OldValues and NewValues Hashtables. They hold the original values and the newly entered ones. They can be accessed as follows:

VB:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs)
    Dim argument As GridBatchEditingEventArgument = TryCast(e.CommandArgument, GridBatchEditingEventArgument)
    Dim oldValues As Hashtable = argument.OldValues
    Dim newValues As Hashtable = argument.NewValues
    Dim newFirstName As String = newValues("FirstName").ToString()
End Sub

Please take a look at this documentation on Server-side API for Batch Editing

Thanks,
Princy 
0
Ralph
Top achievements
Rank 1
answered on 24 Feb 2014, 01:47 PM
I wrote a function in one of my base classes, to do this for any grid.  Wish there was a function like that as a part of GridEditableItem

 
Protected Overridable Sub GetNewValues(ByVal values As Hashtable, ByRef editableItem As GridEditableItem)
 
    For Each value In values
        Try
            editableItem.Item(value.key).text = value.value
        Catch ex As Exception
            'ignore values that do not exist
        End Try
    Next
 
End Sub
0
Angel Petrov
Telerik team
answered on 25 Feb 2014, 11:00 AM
Hi Ralph,

If there is a specific functionality that you would like to be implemented I suggested logging it as a feature request in our feedback portal. That way it will be reviewed by our developers and considered for implementation. The more votes the feedback item receives the higher the chance of including the requested functionality in the next release.

Regards,
Angel Petrov
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ralph
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ralph
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or