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

Batch Update Radgrid

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 04 Dec 2014, 01:44 PM
Hello everybody,

following problem:

I have a RadGrid with a datasource to a custom class. The Grid is in "Batch" edit mode. When I try to save the changes in "itemcommand" event the edititems count are zero. Do u have any ideas?

<telerik:RadGrid runat="server" ID="RadGrid1" ShowFooter="True" AllowFilteringByColumn="false" AllowSorting="True" ExportSettings-FileName="Besuchspruefung"
             OnNeedDataSource="RadGrid1_NeedDataSource" OnBatchEditCommand="RadGrid1_BatchEditCommand" OnItemCommand="RadGrid1_ItemCommand"  OnItemDataBound="RadGrid1_ItemDataBound">
            <MasterTableView AutoGenerateColumns="False"   CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false"  DataKeyNames="besuchID_Ist" EditMode="Batch">
                <BatchEditingSettings OpenEditingEvent="Click" EditType="row" SaveAllHierarchyLevels="false" />

01.Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
02.       Dim u As tmeotUser = CType(Membership.GetUser(), tmeotUser)
03.       Dim con As New ConnectionClass
04. 
05.       If (e.CommandName = "Update") Then
06. 
07.           For Each editedItem As GridEditableItem In RadGrid1.EditItems
08.               Dim newValues As Hashtable = New Hashtable
09. 
10.               'The GridTableView will fill the values from all editable columns in the hash
11.               e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)
12. 
13.                    'perform update
14. 
15.               editedItem.Edit = False
16.           Next
17.       End If
18.       RadGrid1.Rebind()
19.   End Sub

Many thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 09 Dec 2014, 08:17 AM
Hello Jan,

In order to get the new values that are entered you can use the event argument. It is of type GridBatchEditingEventArgument and contains NewValues and OldValues Hashtables. The collections contain the new data and the original values. You can access the values like shown below:

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

If you would like additional information on Batch Editing you would find the following article interesting.

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.

 
Tags
Grid
Asked by
Jan
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or