How do I save 2 radgrids by only 1 outside Button

8 posts, 1 answers
  1. Hiep
    Hiep avatar
    6 posts
    Member since:
    May 2015

    Posted 10 Jun 2015 Link to this post

    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

  2. Answer
    Viktor Tachev
    Admin
    Viktor Tachev avatar
    2491 posts

    Posted 12 Jun 2015 Link to this post

    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
  3. Hiep
    Hiep avatar
    6 posts
    Member since:
    May 2015

    Posted 15 Jun 2015 in reply to Viktor Tachev Link to this post

    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

  4. Hiep
    Hiep avatar
    6 posts
    Member since:
    May 2015

    Posted 17 Jun 2015 Link to this post

    Hi Viktor

    That worked perfectly, thanks so much!

    Hiep

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2491 posts

    Posted 18 Jun 2015 Link to this post

    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
  6. Kathleen Johnson
    Kathleen Johnson avatar
    8 posts
    Member since:
    Apr 2009

    Posted 25 Jul 2017 in reply to Viktor Tachev Link to this post

    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;
                        }
                    }
                }
  7. Anh
    Anh avatar
    1 posts
    Member since:
    Dec 2013

    Posted 05 Oct in reply to Kathleen Johnson Link to this post

    Me too,

    plz share solution for me.

    Thanks !

  8. Vessy
    Admin
    Vessy avatar
    2301 posts

    Posted 08 Oct Link to this post

    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/.

Back to Top