Paging is not working if I rebind the grid.

17 posts, 2 answers
  1. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 29 Oct 2011 Link to this post

    Hi
    I'm using radrgid in my application inside the radpanelbar as one of the radpanelitem.
    I need to get the data from database on regular interval of 2 minutes and need to show in grid without need of refreshing the page.
    For the I'm using Timer and updating the panelbar using asp:updatepanel with conditional updatemode and calling needdatasource event from pageload for every 2 minutes.
    So to have the chages on interval basis I'm rebing the grid.
    But paging is not working. If I dnt rebind the grid I'm not able to see the new chages.
     here is my code of needdatasource event
    DataTable dtConsole = new DataTable();
           DataAccess accessData = new DataAccess();
           try
           {
               dtConsole = accessData.GetData("select consolename from CONSOLE");
               consloeGrid.DataSource = dtConsole;
               //if I dont rebind new data not showing else paging is not working
               consloeGrid.Rebind();
               if (dtConsole.Rows.Count > 10)
               {
                   consloeGrid.AllowPaging = true;
               }
           }
    Please help me as early as possible.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2011 Link to this post

    Hello Ram,

    When are binding the grid with NeedDataSource event, there is no need to explicitly call Rebind() after each operation. The event fires each time after paging, grouping, sorting etc.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 29 Oct 2011 Link to this post

    Thanks for ur quick reply.
    But if don't rebind the grid I'm not able to see the new entry that just added.
    In the table that which I binding to grid has the new entry but in grid its not showing.
    I'm calling the needdatasource event for every 2 or 3 minutes.
    After doing paging only I'm able to see new entry else its not showing
    what should I do.
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 29 Oct 2011 Link to this post

    Hello,

    you can use Advanced Data Binding for automatically handling the paging or handle manually paging.

    Note : for manually binding
    OnPageIndexChanged()
    {
    e.canceld = true;
    dtConsole = accessData.GetData("select consolename from CONSOLE");
    consloeGrid.MasterTableView.CurrentPageIndex =0 ; // new page index
               consloeGrid.DataSource = dtConsole;consloeGrid.DataBind();
    }

    But i suggest you to use advance data binding.

    You can store your data in viewstate/session/cache and achieve your requirement.
    for ex.
    try
           {
               dtConsole = accessData.GetData("select consolename from CONSOLE");
               session["dtConsole"]= dtConsole;
               //if I dont rebind new data not showing else paging is not working
              
               if (dtConsole.Rows.Count > 10)
               {
                   consloeGrid.AllowPaging = true;
               }
               consloeGrid.Rebind();
           }
    ........
    needDataSource()
    {
    consloeGrid.DataSource =session["dtConsole"] as DataTable;
    }




    Thanks,
    Jayesh Goyani
  6. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 29 Oct 2011 Link to this post

    Hii thanks for ur answer.
    Still its not working.
    I don't that  whether I was able to express my problem or not.
    My requirement is.

    First time when page load I will bind table to grid like in needdatasource.
    consolegrid.datasource=dtconsole;
    after 2 or 3 minutes(not refreshing wholepage) I'm calling needdatasource event to bind data and this time datatable having entry if any new data has inserted but for grid its not binding I think.
    But If I call console.rebind() immedialtly after  consolegrid.datasource=dtconsole then its showing new record.
    This time if I do paging its not moving to first page to second means paging not working.
    If I dont call rebind its working.
  7. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 31 Oct 2011 Link to this post

    Hi shinu here is my code

    protected

     

     

    void Page_load(object sender, EventArgs e)

     

    {

     

     

    //set the timer interval

     

    refreshTimer.Interval = 10 * 60 *50;

     

     

    if (Page.IsPostBack)

     

    {

     

     

    GridNeedDataSourceEventArgs GDE = null;

     

    consloeGrid_NeedDataSource(

     

    null, GDE);

     

    }

     

    }

     

     

     

    protected void refreshTimer_Tick1(object sender, EventArgs e)

     

    {

    }


    protected

     

     

    void consloeGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

     

    {

     

     

    DataTable dtConsole=bindGrids("select consolename from CONSOLE");

     

    consloeGrid.DataSource = dtConsole;

     

    if (dtConsole.Rows.Count > 10)

     

    {

    consloeGrid.AllowPaging =

     

    true;

     

    }

     

     

    else

     

    {

    consloeGrid.AllowPaging =

     

    false;

     

    }
    //Here if I rebind() I'm able to see new records. but If rebind the grid paging is not working.Even though I handled pageindexchaged event, its not calling. If I dont rebind paging is working and new records showing only after do paging.
    consoleGrid.Rebind();

    }
    Pleas help me as early as possible since its urgent for me.

  8. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 31 Oct 2011 Link to this post

    Hello,


    set below property in radgrid.

    <telerik:RadGrid  AllowPaging="true" PageSize="10">
              <PagerStyle AlwaysVisible="false" />


    CHeck below link for automatically refresh your grid .
    http://demos.telerik.com/aspnet-ajax/ajax/examples/common/ajaxifytimer/defaultcs.aspx

    Thanks,
    Jayesh Goyani
  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Oct 2011 Link to this post

    Hello Ram,

    If you are using Advanced data binding, the grid will rebind each time after any operation. If you are using timer for rebinding the grid, call Rebind() method in the timer tick event. Check the following demo for more on this.
    Ajax / Ajaxify Timer.

    Thanks,
    Shinu.
  10. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 31 Oct 2011 Link to this post

    Thanks very much.
    It did trik.
  11. Duy
    Duy avatar
    24 posts
    Member since:
    Jun 2013

    Posted 12 Jun 2013 Link to this post

    i was able to get this to work for pageindexchanged. but i can't do this for pagesizechanged, it put me into an infinite loop and then crash with "Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space." error. any idea how to resolve the pagesizechanged Jayesh? thank you for your help.
  12. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 15 Jun 2013 Link to this post

    Hello,

    If possible then can you please provide your code?

    Thanks,
    Jayesh Goyani
  13. Duy
    Duy avatar
    24 posts
    Member since:
    Jun 2013

    Posted 17 Jun 2013 Link to this post

    <telerik:RadPanelBar ID="RadPanelBar1" ExpandMode="MultipleExpandedItems" Width="100%"
        runat="server">
        <Items>
            <telerik:RadPanelItem Expanded="true" Text="Step1" runat="server" Selected="true">
                <Items>
                    <telerik:RadPanelItem Value="New" runat="server">
                        <ItemTemplate>
                            <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" OnPageIndexChanged="RadGrid1_PageIndexChanged">
                                <MasterTableView AutoGenerateColumns="false" HeaderStyle-HorizontalAlign="Center"
                                    DataSourceID="SqlDataSource2" ItemStyle-HorizontalAlign="Center" AlternatingItemStyle-HorizontalAlign="Center">
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID"
                                            ReadOnly="true" />
                                        <telerik:GridBoundColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate"
                                            DataFormatString="{0:MM/dd/yyyy}" />
                                    </Columns>
                                </MasterTableView>
                                <PagerStyle Mode="NextPrevAndNumeric" />
                            </telerik:RadGrid>
                            <asp:Button ID="btn" runat="server" Text="Get Data" OnClick="btn_Click" />
                        </ItemTemplate>
                    </telerik:RadPanelItem>
                </Items>
            </telerik:RadPanelItem>
        </Items>
    </telerik:RadPanelBar>
    Protected Sub RadGrid1_PageSizeChanged(source As Object, e As GridPageSizeChangedEventArgs)
        RadGrid1.CurrentPageIndex = e.NewPageSize
        RadGrid1.DataBind()
    End Sub
    Thank you Yayesh
  14. Eyup
    Admin
    Eyup avatar
    3010 posts

    Posted 20 Jun 2013 Link to this post

    Hi Duy,

    Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
    Declarative DataSource
    Advanced Data Binding

    Hope this helps.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  15. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 20 Jun 2013 Link to this post

    Hello,

    RadGrid will manage all things automatically we do not need manage it manually for Declarative DataSource and Advance Data Binding.

    Please check below link.
    Commands that invoke Rebind() implicitly

    Thanks,
    Jayesh Goyani
  16. John
    John avatar
    43 posts
    Member since:
    Aug 2014

    Posted 02 Sep 2015 in reply to Eyup Link to this post

    Why does Telerik have "Simple Data Binding", if it is apparently such a problem?  Quite often, on many of the forum threads, it is recommended to use Advanced.  They also recommended Adv. DB when getting the Insufficient Stack errors below.  It happens when the user does multiple (4 or more) filter and sort operations on RadGrid.  I switched to OnNeedDataSource, which then points to my BLL, then DAL; but, still no good about 80% of the time.  It will intermittently behave about 20% of the time, whether I use NeedData... or Declarative.  

     

    Some of the forum blogs point to RadScriptManager, as the culprit.  In my Master Page, I have ...

    <telerik:RadScriptManager runat="server" EnableCdn="true" ID="RadScriptManager1" EnablePageMethods="true" />​

     With EnableCdn="true", I get the first error below.  When I set EnableCdn="false", I get the second error message below.  I also set both to false and got the second error message as well.

     

    Another forum blog suggested to view the Call Stack, so I put Breaks in the RadGrid ItemCommand, if (e.CommandName == "Filter" || e.CommandName == "Sort").  The VS Call Stack listed about 20 items.  Stepping beyond the ItemCommand event, it leaves my code and crashes, with an Unhandled exception somewhere in the Telerik assemblies.  How anyone is supposed to diagnose ​an error inside a Telerik dll ... I don't know.  Anyway, it looks like Telerik ASP.Net Ajax is having difficulty with Garbage Collection.  I use version Q3 2014, but, it seems to be happening across multiple versions, because there are many posts about the same thing.  And, to be fair, this might not be a Telerik issue.  It might just be the underlying, less than perfect platform: A​SP.Net/AJAX.

     

    Any help will be appreciated.

    -john-

     

     

    Error #1 ...

    Unhandled exception at line 881, column 13 in http://ajax.aspnetcdn.com/ajax/4.5.1/1/MicrosoftAjaxWebForms.debug.js

    0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.




    Error #2 ...

    Unhandled exception at line 15, column 16485 in http://localhost:49721/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=;;System.Web.Extensions,+Version=4.0.0.0,+Culture=neutral,+PublicKeyToken=31bf3856ad364e35:en-US:88fd0407-24cf-4abd-9df5-22f81b2bc835:ea597d4b:b25378d2;Telerik.Web.UI,+Version=2014.3.1209.45,+Culture=neutral,+PublicKeyToken=121fae78165ba3d4:en-US:cd668efa-682a-4e93-b784-26f0724f247c:16e4e7cd:86526ba7:f7645509:24ee1bba:c128760b:19620875:874f8ea2:f46195d3:92fe8ea0:fa31b949:490a9d4e:bd8f85e4:11a04f7e:1e771326:88144a7a:4cacbc31:2a8622d7:e330518b:2003d0b8:c8618e41:1a73651d:333f8d94:ed16cbdc:8e6f0d33:6a6d718d:58366029:aa288e2d:258f1c72:e4f8f289

    0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.​

     


  17. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1797 posts

    Posted 03 Sep 2015 Link to this post

    Hello John,

    Please refer to the answer in the support ticket that you have opened for the same issue: Ticked ID: 967217.

    If any further questions arise, I would like to suggest that we continue our conversation in the support ticket.


    Regards,
    Konstantin Dikov
    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
  18. John
    John avatar
    43 posts
    Member since:
    Aug 2014

    Posted 11 Sep 2015 in reply to Konstantin Dikov Link to this post

    This turned out to be some bad code, on my part.  I was recursively calling FindControl of an inner-container that was not uniquely named.

    In a support ticket, Konstantin suggested:
    1) "...the error that you are receiving could be due to a infinite loop or endless recursion in your code-behind..."
    2) "...disable the AJAX on your page (by setting the EnableAJAX property of your RadAjaxManager/RadAjaxPanelto false) and see the full stack trace of the error."

    ... which lead me to the resolution.  

    Upon disabling Ajax, I re-tested and caused it to crash with the Insufficient Stack error.  The Stack Trace had 2400+ calls, indicating an infinite loop, mostly of RenderControl event.  Upon some minor Googling, that lead me to FindControl , which lead me to ItemCreate.  My ItemCreate was shared by all (3) RadGrids on (3) tabs, in the same page.  All (3) RadGrids have a NestedViewTemplate, with the same ID="InnerContainer".    I then made the ID unique for each (ie. InnerContainer
    _RadGrid1). 

     

    Thanks, Konstantin!

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017