Prevent Auto Rebinding of Grid

12 posts, 0 answers
  1. Anurag
    Anurag avatar
    3 posts
    Member since:
    Apr 2014

    Posted 02 Apr 2014 Link to this post

    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>
                          
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2014 in reply to Anurag Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anurag
    Anurag avatar
    3 posts
    Member since:
    Apr 2014

    Posted 03 Apr 2014 Link to this post

    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
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Apr 2014 in reply to Anurag Link to this post

    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
  6. Anurag
    Anurag avatar
    3 posts
    Member since:
    Apr 2014

    Posted 04 Apr 2014 Link to this post

    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
  7. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 07 Apr 2014 Link to this post

    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.

     
  8. Kate
    Kate avatar
    7 posts
    Member since:
    Jul 2014

    Posted 29 Jul 2014 in reply to Viktor Tachev Link to this post

    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.
  9. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 01 Aug 2014 Link to this post

    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.

     
  10. Kate
    Kate avatar
    7 posts
    Member since:
    Jul 2014

    Posted 01 Aug 2014 in reply to Pavlina Link to this post

    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 
  11. Albert Shenker
    Albert Shenker avatar
    551 posts
    Member since:
    Mar 2004

    Posted 26 Mar 2015 Link to this post

    When Edit/Cancel are clicked, the grid structure is changed (to show/hide edit fields, forms, etc.). Hence the need to rebind.
  12. Amit
    Amit avatar
    5 posts
    Member since:
    Dec 2013

    Posted 19 Aug 2015 Link to this post

    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

  13. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 24 Aug 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017