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

Prevent Auto Rebinding of Grid

14 Answers 789 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anurag
Top achievements
Rank 1
Anurag asked on 02 Apr 2014, 01:41 PM
We are using a rad grid with edit form that opens in popup on the Edit event of each row. Currently grid refreshes each time the edit link is clicked and take time to open the Popup which is impacting the performance. Moreover if we cancel or close the popup
(handled by cancel event) the grid again refreshes and this action also takes time which in fact should be immediate.

Is there anyway to control the rebind of grid on these events.
Structure of grid:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="radGridComingSoon">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="radGridComingSoon">
                </telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="comingSoonRadAjaxLoadingPanel" runat="server">
</telerik:RadAjaxLoadingPanel>

                            <telerik:RadGrid ID="radGridComingSoon" AllowSorting="True" AllowPaging="True" runat="server"
                                OnItemCreated="radGridComingSoon_ItemCreated" OnItemDataBound="radGridComingSoon_ItemDataBound"
                                GridLines="None" OnInsertCommand="radGridComingSoon_InsertCommand" OnUpdateCommand="radGridComingSoon_UpdateCommand"
                                OnDeleteCommand="radGridComingSoon_DeleteCommand" OnItemCommand="radGridComingSoon_ItemCommand"
                                BorderStyle="Solid" AutoGenerateColumns="false" AllowMultiRowEdit="false" EnableViewState="true"
                                OnPreRender="radGridComingSoon_PreRender" AllowCustomSorting="true">
                                <PagerStyle Mode="NextPrevAndNumeric" PrevPageText="Prev" FirstPageText="First" NextPageText="Next"
                                    LastPageText="Last"></PagerStyle>
                                <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="StandardNumber"
                                    AutoGenerateColumns="false" InsertItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnFirstPage"
                                    EditMode="PopUp">
                                    <EditFormSettings InsertCaption="Add Coming Soon" CaptionFormatString="Edit Coming Soon">
                                        <PopUpSettings Modal="true" Width="742px" Height="1400px" ZIndex="201" />
                                    </EditFormSettings>
                                    <ItemTemplate>
                                        <table class="expandable standards-table">
                                            <tbody>
                                                <tr data-id='<%# Eval("ComingSoonId") %>'>
                                                    <td width="100px">
                                                        <asp:Label runat="server" ID="StandardNumberLabel" Text='<%# Eval("StandardNumber") %>'></asp:Label>
                                                          <td class="icon-column" width="50px" id="tdEditDeleteLink" runat="server">
                                                        <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="Edit" CssClass="Edit-Summary"><i class="icon edit"></i></asp:LinkButton>
                                                        <asp:LinkButton ID="lnkBtnDelete" runat="server" CommandName="Delete" CssClass="delete"><i class="icon remove delete"></i></asp:LinkButton>
                                                    </td>
                                                    <td>
                                                        <asp:Label runat="server" ID="lblChange" Text='<%# Eval("ComingSoonId") %>' CssClass="hide"></asp:Label>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </ItemTemplate>
                                    <Columns>
                                        <telerik:GridTemplateColumn HeaderText="Standard No." SortExpression="StandardNumber"
                                            UniqueName="StandardNumber" DataField="StandardNumber" ItemStyle-CssClass="ColorClass">
                                     
                                        <telerik:GridTemplateColumn HeaderText="ComingSoonId" SortExpression="ComingSoonId"
                                            UniqueName="ComingSoonId" DataField="ComingSoonId" Display="false" EditFormHeaderTextFormat="">
                                        </telerik:GridTemplateColumn>
                                    </Columns>
                                    <NoRecordsTemplate>
                                        <div>
                                            No records to display</div>
                                    </NoRecordsTemplate>
                                    <EditFormSettings EditFormType="Template">
                                        <FormTemplate>
                                            <div class="modal coming-soon-modal">
                                                <h3 class="brand modal-sub-title">
                                                    Brand: <strong>'<%#strBrandName %>'</strong></h3>
                                                <div class="modal-form">
                                                   
                                                        <asp:TextBox ID="txtCompDate" runat="server" CssClass="datepicker"></asp:TextBox>
                                                        <asp:Button ID="btnUpdate" CssClass="btn" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
                                                            runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'>
                                                        </asp:Button>&nbsp;
                                                        <asp:Button ID="btnCancel" Text="Cancel" CssClass="cancel" runat="server" CausesValidation="False"
                                                            CommandName="Cancel"></asp:Button>
                                                    </fieldset>
                                                  
                                                </div>
                                            </div>
                                        
                                        </FormTemplate>
                                    </EditFormSettings>
                                    <CommandItemSettings AddNewRecordText="Add new record" AddNewRecordImageUrl="/_layouts/images/HBSImages/add-record-icon.gif"
                                        RefreshText="Refresh" RefreshImageUrl="/_layouts/images/HBSImages/refresh-icon.gif"
                                        ShowRefreshButton="false"></CommandItemSettings>
                                </MasterTableView>
                                <ClientSettings>
                                    <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
                                </ClientSettings>
                            </telerik:RadGrid>
                      

14 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Apr 2014, 05:29 AM
Hi Anurag,

The commands like Edit, Update, Cancel etc grid commands make an implicit call to the Rebind() method of RadGrid in order to refresh the control's content and fetch the latest information from the grid source. Take a look at this article to more about Commands that invoke Rebind() implicitly.
You can check this topics under performance to have grid performance optimizations.

Thanks,
Princy
0
Anurag
Top achievements
Rank 1
answered on 03 Apr 2014, 03:06 PM
Hi Princy,

Is there any way to prevent the grid from rebinding itself. I mean the grid should  rebind only in scenarios where i want to get it rebinded thus reducing the database calls. I mean there is no need to bind the grid on edit and cancel event in the above example. how to handle this???

regards
Anurag Chauhan
0
Princy
Top achievements
Rank 2
answered on 04 Apr 2014, 05:56 AM
Hi Anurag,

You may try to disable the ViewState. As mentioned in the documentation, when RadGrid's ViewState is turned off, the NeedDataSource event does not fire after any of the commands. If you want to make the event fire in such scenarios, you need to first set RadGrid's DataSource to null/Nothing and then call Rebind(). Have a look at this article on Rebind grid on command/postback event with EnableViewState = false.

Thanks,
Princy
0
Anurag
Top achievements
Rank 1
answered on 04 Apr 2014, 03:16 PM
Hi Princy,

I have already tried the above mentioned solution but as we are using edit forms in a popup to edit the grid record this solution does not work . When the record is updated in the edit form popup it does not get saved and also new records are also not inserted. And also the grid is rebinded after any event with databindreason postbackviewstatenotpersisted.

Regards
Anurag
0
Viktor Tachev
Telerik team
answered on 07 Apr 2014, 12:46 PM
Hi Anurag,

RadGrid is designed so that it needs to call it's Rebind() method when the commands listed in this article are fired. If the grid performance is slow try implementing the approaches listed in the performance optimization article suggested by Princy.

Additionally you could try using custom paging in RadGrid so that only data for the items on the current page is retrieved from the database. There is also an online demo that illustrates custom paging for RadGrid.

Alternatively you might also consider using Batch editing for RadGrid. This editing mode allows the user to make multiple changes and then submit them with a single request to the server.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kate
Top achievements
Rank 1
answered on 29 Jul 2014, 01:45 PM
I have the exact same concern as Anurag. Why should it be necessary to rebind the grid if you click cancel.. or just clicking edit? I can see it rebinding on Update but not Edit and Cancel. The data is already there for those events.

Is there any way to manually suppress this call to rebind on Edit or Cancel?

I have a dynamic datatable built from disparate queries so it's really tough to implement other suggestions as I have to pull it all back and build the DataTable which I then bind to the grid. I just want to suppress all these unnecessary rebinds and only rebind if a record is Updated.
0
Pavlina
Telerik team
answered on 01 Aug 2014, 02:17 PM
Hello Kate,

As my colleague Viktor already pointed RadGrid is designed so that it needs to call it's Rebind() method when the commands listed in Commands that invoke Rebind() implicitly article are fired.

Regarding Edit and Cancel commands it is also necessary to rebind the grid when they fired. Note that all the commands that change the grid structure need rebind. When you click Edit the grid should create the editors and when Cancel is clicked they should be removed, otherwise the editors will not open and respectively will not close on Cancel. 

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kate
Top achievements
Rank 1
answered on 01 Aug 2014, 02:31 PM
Hi Pavlina,
I don't see the need to rebind on Edit and Cancel. Update, yes. But on edit the grid is just reading the values and putting them in textboxes and on cancel nothing is changing.

It's kind of a moot point I guess since that's the way the control works whether it makes sense or not :) I have put a workaround in place for large data sets.

Thanks,
Kate 
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 26 Mar 2015, 11:47 AM
When Edit/Cancel are clicked, the grid structure is changed (to show/hide edit fields, forms, etc.). Hence the need to rebind.
0
Amit
Top achievements
Rank 1
answered on 19 Aug 2015, 09:13 PM

Is there any update on this issue ? I am having similar issue where radgrid loses all selected items when a pop up control opens through edit form settings. 

 Any help would be appreciated. 

 

Regards

0
Viktor Tachev
Telerik team
answered on 24 Aug 2015, 10:53 AM
Hello Amit,

The RadGrid control needs to initiate postback when the Edit/Insert form is created. Thus, the control is also rebound. This is the default behavior with server-side binding.

If you would like to persist the selected items in RadGrid after postback you should use the approach described in the article below:



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
Carl
Top achievements
Rank 1
answered on 06 Sep 2017, 11:04 AM

We are having a similar issue.  We have a template column in the grid with a button that opens a bootstrap modal.  The grid is ajaxified.  When the template column button is clicked it reloads the grid.  This causes latency on loading data in the modal.

As the button is in an ajaxified grid I get what its doing, but how can we exclude a control inside the grid from this?

 

0
Eyup
Telerik team
answered on 12 Sep 2017, 06:39 AM
Hi Carl,

You can achieve this requirement using one of the approaches suggested in this article:
http://docs.telerik.com/devtools/aspnet-ajax/controls/ajax/how-to/exclude-controls-from-ajaxifying

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
M
Top achievements
Rank 1
answered on 15 Sep 2017, 05:22 PM

Rebinding the grid on commands such as Edit may be fine (and understandable), however the telerik implementation has the following logical flaw.

In a real world scenario where multiple users/processes may be creating/deleting records, the rebind can cause the grid's editindexes to become meaningless and potentially cause the wrong griditem to be edited.

In the case where User A visits the page with the grid, then User B creates a new record but then User A clicks "edit" - the wrong item goes into edit-mode.

 

Tags
Grid
Asked by
Anurag
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Anurag
Top achievements
Rank 1
Viktor Tachev
Telerik team
Kate
Top achievements
Rank 1
Pavlina
Telerik team
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Amit
Top achievements
Rank 1
Carl
Top achievements
Rank 1
Eyup
Telerik team
M
Top achievements
Rank 1
Share this question
or