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

Batch Editing issue

2 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nelbin
Top achievements
Rank 1
Nelbin asked on 18 Nov 2013, 02:33 AM
Good Day,

I have this gridview which gets databinded with two rows(and two columns)

 <telerik:RadGrid ID="RadGrid3" runat="server" AllowAutomaticUpdates="False" AllowPaging="True" AllowAutomaticInserts="false">
                                    <MasterTableView EditMode="Batch" CommandItemDisplay=Top HorizontalAlign="NotSet" AutoGenerateColumns="False" DataKeyNames="Language">
                                        <BatchEditingSettings EditType="Cell" />
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="Language" HeaderStyle-Width="210px" HeaderText="Language"
                                                SortExpression="CodeLang" UniqueName="Language" ReadOnly="True">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Translation" HeaderStyle-Width="210px" HeaderText="Translation"
                                                SortExpression="Translation" UniqueName="Translation">
                                            </telerik:GridBoundColumn>


                                        </Columns>
                                    </MasterTableView>
                                </telerik:RadGrid>

As you can see batchediting is enabled and I have no problems anymore with that(I can edit the text on the current gridview)

My problem is when I update the gridview. It seems that I do not obtain the contents of the Translation column. I got an idea based on your documentation link http://www.telerik.com/help/aspnet-ajax/grid-insert-update-delete-at-database-level.html but I always get an out of bounds issue(because the control count is 0). I tried using e.Item.cells but still the string I input in the Translation column isn't being passed in the codebehind(it returns "" or nothing). Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Nov 2013, 04:04 AM
Hi Nelbin,

You can use the OnBatchEditCommand event of the RadGrid to perform operations from codebehind. Please try the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnBatchEditCommand="RadGrid1_BatchEditCommand" . . .>
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top" >
        <BatchEditingSettings OpenEditingEvent="Click" EditType="Cell" />
        <Columns>
         . . .  
        </Columns>
    </MasterTableView>   
</telerik:RadGrid>

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 Translation= newValues["Translation"].ToString();
          
            try
            {
                //Code to update to DB
            }
            catch (Exception ex)
            {
               //Exception Message
            }
        }
    }
}

Thanks,
Princy
0
Nelbin
Top achievements
Rank 1
answered on 18 Nov 2013, 06:51 AM
Thanks Princy, works like a charm :)

and those who need the same answer in VB here's the code:


Protected Sub RadGrid1_BatchEditCommand(sender As Object, e As GridBatchEditingEventArgs)
For Each command As GridBatchEditingCommand In e.Commands
If (command.Type = GridBatchEditingCommandType.Update) Then
Dim newValues As Hashtable = command.NewValues
Dim oldValues As Hashtable = command.OldValues
Dim Translation As String = newValues("Translation").ToString()

'Code to update to DB
Try
'Exception Message
Catch ex As Exception
End Try
End If
Next
End Sub
Tags
Grid
Asked by
Nelbin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nelbin
Top achievements
Rank 1
Share this question
or