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

Save Multiple Grids in Batch Edit Mode and Data From Other Controls with one Button Click

7 Answers 380 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 22 Oct 2015, 02:20 PM

Hello,

I have two grids with EditMode="Batch".  Both grids subscribe to the OnBatchEditCommand event for saving data.  I am trying to save data from both of these grids, as well as data from other controls on the page with one button click. 

I have tried suggestions from http://www.telerik.com/forums/save-radgrid-in-batcheditmode-from-external-button and http://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button but can't seem to achieve the desired functionality...  Is this possible?

Thank you in advance.

Amy

 

7 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 23 Oct 2015, 01:00 PM
Hi Amy,

The suggestion provided in the forum thread below works perfectly on my end:
http://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button

Can you please share your page markup and related code behind that demonstrates the issue in this example? Thus we can revise them locally and advise you further.

Regards,
Maria Ilieva
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
Amy
Top achievements
Rank 1
answered on 23 Oct 2015, 01:52 PM

Hi Maria,

Thank you for your response.  I just tested again and it seems that the example from the link you mentioned does in fact save the data from both grids.  However, the first grid does not refresh with the updates so it looks like the data wasn't saved.  If I refresh the page (by navigating to the same page in the browser address bar), then the grid shows the new data...
I've included the relevant markup/code below. Any suggestions why the first grid is not displaying the new data?
(Note that this code is being used in a user control in a SharePoint 2013 web part.)

 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function saveAllChanges() {
            var grid1 = $find("<%= gridGoals.ClientID %>");
            var masterTable1 = grid1.get_masterTableView();
            var grid2 = $find("<%= gridMentions.ClientID %>");
            var masterTable2 = grid2.get_masterTableView();
            var batchEditManager = grid2.get_batchEditingManager();
            var tables = [];
            tables.push(masterTable1);
            tables.push(masterTable2);
            batchEditManager.saveTableChanges(tables);
        }
    </script>
</telerik:RadCodeBlock>
 
<div class="LayoutSubHeader">
    <asp:Panel ID="pnlButtons1" runat="server" Visible="false" CssClass="ButtonContainer">
        <div style="color: #666666; padding: 5px;">
            <asp:Label ID="lblLastSavedTime1" runat="server" Font-Bold="true" visible="false" />
        </div>
        <div>
            <asp:Button ID="btnSave1" runat="server" Text="Save All" OnClientClick="saveAllChanges(); return false;" />  
            <asp:Button ID="btnClear1" runat="server" Text="Clear Changes" OnClick="btnClear_Click" />
        </div>
    </asp:Panel>
</div>
<div class="LayoutBodyLeft">
    <asp:Panel ID="pnlEmployeeNotes" runat="server" CssClass="SectionContainer">
        <div class="SectionHeader">
            Employee Notes
        </div>
        <div class="QuestionContainer">
            What accomplishments are you proud of?
        </div>
        <div class="AnswerContainer">
            <div class="EditorContainer">
                <telerik:RadEditor ID="editorAccomplishments" runat="server" Height="250px" Width="100%"
                    ToolsFile="/_controltemplates/15/PerformanceManager.WebParts/EmployeeAppraisal/EditorTools.xml"
                    NewLineMode="Div" EnableResize="false" Skin="Silk">
                    <CssFiles
                        <telerik:EditorCssFile Value="/_controltemplates/15/PerformanceManager.WebParts/EmployeeAppraisal/Editor.css" />                     
                    </CssFiles>
                </telerik:RadEditor>
            </div>
        </div>
        <div class="QuestionContainer">
            What do you want to learn or improve in the next period?
        </div>
        <div class="AnswerContainer">
            <div class="EditorContainer">
                <telerik:RadEditor ID="editorImprovements" runat="server" Height="250px" Width="100%"
                    ToolsFile="/_controltemplates/15/PerformanceManager.WebParts/EmployeeAppraisal/EditorTools.xml"
                    NewLineMode="Div" EnableResize="false" Skin="Silk">
                    <CssFiles
                        <telerik:EditorCssFile Value="/_controltemplates/15/PerformanceManager.WebParts/EmployeeAppraisal/Editor.css" />                     
                    </CssFiles>
                </telerik:RadEditor>
            </div>
        </div>
        <div class="QuestionContainer">
            Goals
        </div>
        <div class="AnswerContainer">
                <telerik:RadGrid ID="gridGoals" runat="server"
                    AllowSorting="true"
                    AutoGenerateColumns="false"
                    EnableHeaderContextMenu="true"
                    OnNeedDataSource="gridGoals_NeedDataSource" OnBatchEditCommand="gridGoals_BatchEditCommand" OnPreRender="gridGoals_PreRender"
                    GridLines="None"
                    HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px" HeaderStyle-BorderColor="White"
                    PageSize="25" Width="100%" Skin="Silk">
                    <MasterTableView Name="Master" AllowMultiColumnSorting="true" ShowHeadersWhenNoRecords="true" EnableNoRecordsTemplate="true"
                        CommandItemDisplay="Bottom" EditMode="Batch" DataKeyNames="ID">
                        <BatchEditingSettings OpenEditingEvent="Click" EditType="Cell" />
                        <CommandItemSettings ShowSaveChangesButton="false" ShowCancelChangesButton="false" ShowRefreshButton="false" AddNewRecordText="Add new goal" />
                        <Columns>
                            <telerik:GridBoundColumn HeaderText="Description" DataField="JGoalDescription" UniqueName="JGoalDescription"></telerik:GridBoundColumn>                         
                            <telerik:GridDateTimeColumn HeaderText="Date Established" HeaderStyle-Width="200px" DataField="JGoalDateEstablished" UniqueName="JGoalDateEstablished" DataType="System.DateTime" DataFormatString="{0:yyyy-MM-dd}"></telerik:GridDateTimeColumn>
                            <telerik:GridDateTimeColumn HeaderText="Estimated Completion Date" HeaderStyle-Width="200px" DataField="JGoalDateCompleted" UniqueName="JGoalDateCompleted" DataType="System.DateTime" DataFormatString="{0:yyyy-MM-dd}"></telerik:GridDateTimeColumn>
                            <telerik:GridButtonColumn ConfirmText="Delete this goal?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px"
                                ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>
                        </Columns>
                        <NoRecordsTemplate>
                            <div>
                                There are no goals to display for this period.
                            </div>
                        </NoRecordsTemplate>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true" Resizing-AllowColumnResize="true" Resizing-EnableRealTimeResize="true" Resizing-AllowResizeToFit="true" Resizing-ClipCellContentOnResize="false">
                    </ClientSettings>
                </telerik:RadGrid>
        </div>
    </asp:Panel>
    <asp:Panel ID="pnlSupervisorNotes" runat="server" Visible="false" CssClass="SectionContainer" BackColor="#FFDA3F">
        <div class="SectionHeader">
            Supervisor Notes
        </div>
        <div class="QuestionContainer">
            Continue to
        </div>
        <div class="AnswerContainer">
            <div class="EditorContainer">
                <telerik:RadEditor ID="editorContinueTo" runat="server" Height="250px" Width="100%"
                    ToolsFile="/_controltemplates/15/PerformanceManager.WebParts/EmployeeAppraisal/EditorTools.xml"
                    NewLineMode="Div" EnableResize="false" Skin="Silk">
                    <CssFiles
                        <telerik:EditorCssFile Value="/_controltemplates/15/PerformanceManager.WebParts/EmployeeAppraisal/Editor.css" />                     
                    </CssFiles>
                </telerik:RadEditor>
            </div>
        </div
    </asp:Panel>
</div>
<div class="LayoutBodyRight">
    <div class="SectionContainer">
        <div class="SectionHeader">
            Mentions ...
        </div>
        <div class="AnswerContainer">
                <telerik:RadGrid ID="gridMentions" runat="server"
                    AllowSorting="true"
                    AutoGenerateColumns="false"
                    EnableHeaderContextMenu="true"
                    OnNeedDataSource="gridMentions_NeedDataSource" OnBatchEditCommand="gridMentions_BatchEditCommand" OnPreRender="gridMentions_PreRender"
                    GridLines="None"
                    HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px" HeaderStyle-BorderColor="White"
                    PageSize="25"
                    Width="100%"
                    Skin="Silk">
                    <MasterTableView Name="Master" AllowMultiColumnSorting="true" ShowHeadersWhenNoRecords="true" EnableNoRecordsTemplate="true"
                        CommandItemDisplay="Bottom" EditMode="Batch" DataKeyNames="ID">
                        <BatchEditingSettings OpenEditingEvent="Click" EditType="Cell" />
                        <CommandItemSettings ShowSaveChangesButton="false" ShowCancelChangesButton="false" ShowRefreshButton="false" AddNewRecordText="Add new mention" />
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="Who?" DataField="JMentioned" UniqueName="JMentioned">
                                <ItemTemplate>
                                    <%# Eval("JMentioned") %>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox runat="server" ID="cbMentioned" EmptyMessage="Choose an Employee" MarkFirstMatch="true" Filter="StartsWith">
                                    </telerik:RadComboBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn HeaderText="Why?" DataField="JMentionedReason"></telerik:GridBoundColumn>
                            <telerik:GridButtonColumn ConfirmText="Delete this mention?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px"
                                    ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>
                        </Columns>
                        <NoRecordsTemplate>
                            <div>
                                There are no mentions to display for this period.
                            </div>
                        </NoRecordsTemplate>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true" Resizing-AllowColumnResize="true" Resizing-EnableRealTimeResize="true" Resizing-AllowResizeToFit="true" Resizing-ClipCellContentOnResize="false">
                    </ClientSettings>
                </telerik:RadGrid>
        </div>
    </div>
</div>
<asp:HiddenField ID="hiddenSaveChanges" runat="server" Value="false" />

protected void Page_PreRender(object sender, EventArgs e)
{
    if (hiddenSaveChanges.Value == "true")
    {
        try
        {
            SaveEmployeeNotes(); // Save data from other controls here...
            SaveSupervisorNotes(); // Save data from other controls here...
            string lastSaved = string.Format("Last saved:  {0}", DateTime.Now.ToString("yyyy-MM-dd hh:mm tt"));
            lblLastSavedTime1.Text = lastSaved;
            lblLastSavedTime1.Visible = true;
        }
        catch (Exception ex)
        {
            hiddenSaveChanges.Value = "false";
            // log error
        }
    }
    hiddenSaveChanges.Value = "false";
}
 
protected void gridGoals_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    //Load data here ...
}
 
protected void gridGoals_PreRender(object sender, EventArgs e)
{
    RadDatePicker pickerEstablished = GetGoalDatePickerControl("JGoalDateEstablished");
    pickerEstablished.DateInput.DateFormat = "yyyy-MM-dd";
    pickerEstablished.DateInput.DisplayDateFormat = "yyyy-MM-dd";
    RadDatePicker pickerCompleted = GetGoalDatePickerControl("JGoalDateCompleted");
    pickerCompleted.DateInput.DateFormat = "yyyy-MM-dd";
    pickerCompleted.DateInput.DisplayDateFormat = "yyyy-MM-dd";
}
 
protected void gridGoals_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
    hiddenSaveChanges.Value = "true";
     
    //Handle the grid updates
    foreach (GridBatchEditingCommand command in e.Commands)
    {
        try
        {
            Hashtable newValues = command.NewValues;
 
            if (command.Type == GridBatchEditingCommandType.Insert)
            {
                // Add new record here...
            }
            else if (command.Type == GridBatchEditingCommandType.Update)
            {
                // Update record here ...
            }
            else if (command.Type == GridBatchEditingCommandType.Delete)
            {
                // delete record here ..
            }
        }
        catch (Exception ex)
        {
            // log error
        }
    }           
}
 
protected void gridMentions_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    //Load data here ...
}
 
protected void gridMentions_PreRender(object sender, EventArgs e)
{
    // Load data for RadComboBox in EditItemTemplate here ...
}
 
protected void gridMentions_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
    hiddenSaveChanges.Value = "true";
     
    //Handle the grid updates
    foreach (GridBatchEditingCommand command in e.Commands)
    {
        try
        {
            Hashtable newValues = command.NewValues;
 
            if (command.Type == GridBatchEditingCommandType.Insert)
            {
                // Add new record here...
            }
            else if (command.Type == GridBatchEditingCommandType.Update)
            {
                // Update record here ...
            }
            else if (command.Type == GridBatchEditingCommandType.Delete)
            {
                // delete record here ..
            }
        }
        catch (Exception ex)
        {
            // log error
        }
    }     
 }

0
Amy
Top achievements
Rank 1
answered on 27 Oct 2015, 02:00 PM

Hi Maria,

Were you able to reproduce my issue regarding the first grid not displaying the updated data?  Or, can you suggest a solution that would allow me to manually rebind the grid after saving using the method I posted above?

 

Thanks,

Amy

0
Maria Ilieva
Telerik team
answered on 28 Oct 2015, 09:42 AM
Hello,

The code you have provided looks absolutely correct to me and the issue can not be replicated in sample project that uses this approach.
I would suggests you to remove the try catch blocks from the BatchEditCommand events and see if any error appear on the page. Also if you have ajax on the page, try to disable it and see how it goes.
You can also try to manually call Rebind() for the first grid in its BatchEditCommand event and see if this helps.

Regards,
Maria Ilieva
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
Amy
Top achievements
Rank 1
answered on 28 Oct 2015, 01:36 PM

Hello Maria,

I had already tried to manually call Rebind() using the code above, but it didn't help.

The only way I am able to get both grids to rebind is to set the grid's EnableViewState property to false, and then rebind the grid on the Page_PreRender event as shown here - http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/performance/rebind-grid-with-enableviewstate-=-false.  Not entirely sure why this is...

Amy

 

0
Maria Ilieva
Telerik team
answered on 30 Oct 2015, 12:32 PM
Hello Amy,

As the issue you are facing is rather strange and there is no obvious reason for it in the demonstrated code it will be best of you can open a regular support ticket and send us sample runnable version of your application that demonstrates the issue. Thus we will be able to revise it locally and advise you further.


Regards,
Maria Ilieva
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:24 PM

Hi, Maria, I facing an issue trying to save two grids in batch edit mode. Here is a link to my issue http://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button#-EZxg2vVKkqERtTkc7QI1w

 

Please help!

Tags
Grid
Asked by
Amy
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Amy
Top achievements
Rank 1
Kathleen Johnson
Top achievements
Rank 1
Share this question
or