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

How do I save 2 radgrids by only 1 outside Button

7 Answers 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hiep
Top achievements
Rank 1
Hiep asked on 11 Jun 2015, 03:35 AM

Hi, I'm having 2 radgrids (rgRole and rgRecei) in batch edit mode on same page.I'm using 1 html button to call OnBatchEditCommand from outside to save it. But my problem is that it can call only 1 of second radgrid and dismiss the first one. 

function SaveRg() {
            $find('rgRole').get_batchEditingManager().saveChanges('rgRole_ctl00')
            $find('rgRecei').get_batchEditingManager().saveChanges('rgRecei_ctl00');
            return false;
        }

So how do i get NewValues of radgrid in code behind in another function like 

protected void getRadGridNewValues(){

 // get newValue of rgRole here

// get newValue of rgRecei here

}

Any help appreciated,
Thanks,
Hiep

7 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 12 Jun 2015, 12:51 PM
Hello Hiep,

In order to save the data for multiple RadGrid controls with a single click you can use the saveTableChanges() method. Check out the following code snippets that illustrate the approach.

Markup:

<asp:Button Text="Save All" runat="server" ID="Button1" OnClientClick="clientClick(); return false;" />

JavaScript

function clientClick() {
                    var grid1 = $find("<%= RadGrid1.ClientID %>");
                    var masterTable1 = grid1.get_masterTableView();
 
                    var grid2 = $find("<%= RadGrid2.ClientID %>");
                    var masterTable2 = grid2.get_masterTableView();
                    var batchEditManager = grid2.get_batchEditingManager();
                    var tables = [];
 
                    tables.push(masterTable1);
                    tables.push(masterTable2);
 
                    batchEditManager.saveTableChanges(tables);
 
                }


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
Hiep
Top achievements
Rank 1
answered on 16 Jun 2015, 04:35 AM

Hi Viktor

I saw your point but what i need is get value in behind code, because i have to handle and validate it. Can you give me a demo use OnClick event. 

Thanks,

Hiep

0
Hiep
Top achievements
Rank 1
answered on 17 Jun 2015, 08:57 AM

Hi Viktor

That worked perfectly, thanks so much!

Hiep

0
Viktor Tachev
Telerik team
answered on 18 Jun 2015, 12:03 PM
Hello Hiep,

I am glad to hear that the suggestion was helpful to you. In case you have further queries do not hesitate to contact us again.

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
Kathleen Johnson
Top achievements
Rank 1
answered on 25 Jul 2017, 03:14 PM

Hi, Viktor, I followed the instructions to save both grids but in the code behind, my Command object is not correct. Instead of "Insert" commandtype, I get Update and old and new values are empty. Please help!

Command object in debugger:

e.Commands[0]
{Telerik.Web.UI.GridBatchEditingCommand}
    Arguments: Count = 4
    Canceled: false
    Item: null
    NewValues: null
    OldValues: Count = 0
    OwnerTableView: {Telerik.Web.UI.GridTableView}
    Type: Update

 

C# code:

protected void gridBenefitVerification_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
        // Benefit Verification data
        for (int i = 0; i < e.Commands.Count; i++)
        {
            var currentCommand = e.Commands[i];
            if (currentCommand.Type == GridBatchEditingCommandType.Insert)
            {
                EscalationCaseBv escalationBv = EscalationCaseBv.NewEscalationCaseBv();
                escalationBv.EscalationCaseId = Convert.ToInt64(ViewState["escalationCaseId"]);
                escalationBv.DateVerified = Convert.ToDateTime(currentCommand.NewValues["DateVerified"]);
                escalationBv.CreateUser = Session["username"].ToString();
                escalationBv.Update();
            }
        }
 
        ViewState["BVs"] = EscalationCaseBvCollection.GetEscalationCaseBvCollection(Convert.ToInt64(ViewState["escalationCaseId"]));
    }

 

Javascript Code:

function saveChanges() {
                if (Page_IsValid) {
                    <%--var grid = $find("<%= gridPrescriptions.ClientID %>");
                    if (grid.get_masterTableView().get_dataItems().length > 0) {
                        grid.get_batchEditingManager().saveChanges(grid.get_masterTableView());
                    }
                    else {
                        var label = document.getElementById("<%= lblMessage.ClientID%>");
                        label.innerText = "Please add at least one prescription.";
                        label.style.color = "red";
                        label.style.display = "";
                        document.body.scrollTop = document.documentElement.scrollTop = 0;
                    }--%>
 
                    var gridRx = $find("<%= gridPrescriptions.ClientID %>");
                    var masterTableRx = gridRx.get_masterTableView();
 
                    if (masterTableRx.get_dataItems().length > 0) {
 
                        var gridBv = $find("<%= gridBenefitVerification.ClientID %>");
                        var masterTableBv = gridBv.get_masterTableView();
                        var batchEditManager = gridBv.get_batchEditingManager();
                        var tables = [];
 
                        var changes1 = gridBv.get_batchEditingManager()._changes;
                        var changes2 = gridRx.get_batchEditingManager()._changes;
 
                        tables.push(masterTableRx);
                        tables.push(masterTableBv);
 
                        batchEditManager.saveTableChanges(tables);
                    }
                    else
                    {
                        var label = document.getElementById("<%= lblMessage.ClientID%>");
                        label.innerText = "Please add at least one prescription.";
                        label.style.color = "red";
                        label.style.display = "";
                        document.body.scrollTop = document.documentElement.scrollTop = 0;
                    }
                }
            }
0
Anh
Top achievements
Rank 1
answered on 05 Oct 2020, 11:21 AM

Me too,

plz share solution for me.

Thanks !

0
Vessy
Telerik team
answered on 08 Oct 2020, 08:22 AM

Hi Anh,

Did you try the solution provided by Viktor on 12th of June? - https://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button#bJYgYZ3sh0iEDanQql6cwQ

If it is not working for your scenario, please, send me a sample where I can examine the setup that you have and see why the suggested approach is not behaving as expected.

Regards,
Vessy
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
Hiep
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Hiep
Top achievements
Rank 1
Kathleen Johnson
Top achievements
Rank 1
Anh
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or