Batch edit insert : New values are empty with CommandItemTemplate

1 Answer 85 Views
Grid
Fabien
Top achievements
Rank 1
Fabien asked on 15 Dec 2022, 11:32 AM

Hello,

i worked on radgrid with batch edit commands : Add, Save and Cancel.

It works fine with inherited buttons, but when i try to have CommandItemTemplate buttons, it doesn't work for the add button.

 

When i click on the add button, i t's calling this function :

grid.get_batchEditingManager().addNewRecord(grid.get_masterTableView());

An added line, empty, is shown in radgrid, it's ok.

But then, i click on the save button, to save the data added, and it's calling this function :

grid.get_batchEditingManager().saveChanges(grid.get_masterTableView());

The problem is that in my server code, in BatchEditCommand(sender As Object, e As Telerik.Web.UI.GridBatchEditingEventArgs), command.NewValues is null and also command.type is UPDATE and not INSERT.

In spy mode, i saw the data i want to add in command.Arguments, but i cannot access them.

What am i doing wrong ?

Thanks in advance.

Freddy (from France)

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 20 Dec 2022, 08:51 AM

Hello Fabien,

For the Grid to send the values to server, the Columns must have the DataField set for the Columns.

Example using both GridBoundColumn and a GridTemplateColumn:

<telerik:GridBoundColumn DataField="ShipName"></telerik:GridBoundColumn>

<telerik:GridTemplateColumn DataField="ShipName">
    <ItemTemplate>
        <%# Eval("ShipName") %>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadTextBox ID="RadTextBox1" runat="server"></telerik:RadTextBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

 

The PostBack needs to be turned off for both the "Add" and "Save Changes" buttons

Example

<CommandItemTemplate>
    <telerik:RadButton runat="server" ID="RadButton1" Text="Add New Records" AutoPostBack="false" OnClientClicked="addNewRecords" />
    <telerik:RadButton runat="server" ID="RadButton2" Text="Save Changes" AutoPostBack="false" OnClientClicked="saveChanges" />
</CommandItemTemplate>

 

The Script

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

 

After the "Add" button is clicked, you will need to fill in the values

 

When done setting the values, click "Save Changes" and expect the values to be submitted to the server (BatchEditCommand event)

 

For more details, you can check out the following articles:

 

If you're still experiencing issues, please share the Grid setup you have (markup code and C#/VB) and we'll check why it wouldn't work.

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Fabien
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or