none
Creating custom paging buttons for ReportViewer Control RRS feed

  • Question

  • I'm creating a custom web application and hiding the report viewer toolbar and creating my own, however, i'm having problems creating paging buttons for Previous and Next to move through a report with multiple pages.

     

    It seems the GetTotalPages() function is always behind from the last report so it gives the the old page count. (at least on drill through reports). I'm using the GetTotalPages() to deterimine if the "next" and "prev" buttons should display and the CurrentPage to determine if the "next" and "prev" buttons are enabled/disabled depending on the page it is on.

     

    Note: Also, i'm using the Report Services Web Service for consuming reports via a web app that connects to the report server.

     

    What am I doing wrong? Is there a way to acomplish this?

     

    Here is the code i'm using:

     

    protected void Page_Load(object sender, EventArgs e)

    {

    if (ReportViewer1.ServerReport.GetTotalPages() > 1)

    {

    btnPrevious.Visible = true;

    btnNext.Visible = true;

    if (ReportViewer1.CurrentPage > 1)

    {

    btnPrevious.Enabled = true;

    }

    else

    {

    btnPrevious.Enabled = false;

    }

    if (ReportViewer1.CurrentPage < ReportViewer1.ServerReport.GetTotalPages())

    {

    btnNext.Enabled = true;

    }

    else

    {

    btnNext.Enabled = false;

    }

    }

    else

    {

    btnPrevious.Visible = false;

    btnNext.Visible = false;

    }

    }

     

     

    protected void btnPrevious_Click(object sender, EventArgs e)

    {

    ReportViewer1.CurrentPage = --ReportViewer1.CurrentPage;

    }

     

    protected void btnNext_Click(object sender, EventArgs e)

    {

    ReportViewer1.CurrentPage = ++ReportViewer1.CurrentPage;

    }

    Friday, April 25, 2008 4:40 PM

All replies

  • try to do this on RenderingComplete event

    Friday, May 16, 2008 7:24 AM
  • I'm not seeing this event on the Microsoft.Reporting.WebForms ReportViewer Control.
    Monday, June 30, 2008 9:33 PM
  • If you are using the viewer in synchronous mode (ReportViewer.AsyncRendering == false), the viewer will process the report during its PreRender event.  The updated page count will be available after that event has fired.

    If you are using the viewer in asynchronous mode, the report isn't processed during the ASPX page execution.  Instead, it happens on the ReportViewer http handler.  In this case, there is no supported way to get the updated page count, though it is something we intend to address in the next version.

    Thursday, July 3, 2008 2:07 AM
    Moderator
  • I have the same problem. I have to build a own paging solution, as the paging controls in IE in anynymous Access within MOSS are not working propertly.
    In Firefox, by the way, the paging controls are working.

    So I am trying to build an own paging, but the GetTotalPages() Method doesn´t get the total page number. The return is always 0.
    I tried several EventMethods, but even in PreRender the GetTotalPages() is 0.

    In an postback after the report has been rendered, the Method get the real number of pages.

    @Brian: You mentiad in Async = false, the page count will be right AFTER the PreRender. Wich EventHandler in the Page-Load-Cycle is called after the PreRender??
    Monday, November 9, 2009 10:26 AM
  • Hi,
    Even i am facing the same problem.
    I have to implment custom page navigation.
    Can anyone help me how to show the total number of pages?

    Thanks in Advance!!

    Siva
    Friday, December 11, 2009 10:03 AM
  • Hi siva and david, the only event that fires after prerender (but before render) is SaveStateComplete (at least according to http://msdn.microsoft.com/en-us/library/ms178472.aspx). I have successfully used this event and the CurrentPage property & GetTotalPages() method to make custom paging buttons.

    Doesnt seem quite the nicest place to put it but it seems to be the only option.

    So basically set AsyncRendering to false and attach a method to the SaveStateComplete event that sets up your paging buttons/labels.

    Tromm


    Monday, January 4, 2010 5:57 PM
  • Can we assign TotalPages to the MS reportviewer to do paging manually(custom paging).

    My condition is like this i have millions of records to show in MS Report. So if we fetch all records at a time then time out error will be thrown.

    So I want to do custom paging so i can calculate the TotalPages and assign to the MS reportviewer and I will show few of data(suppose top 100 then for next page next 100 records). So if user click on next page i will send the page index and fetch the records accordinglly.

    Is it possible in MS reportviewer?

    Please help me out on this issue.
    Thursday, May 23, 2013 12:54 PM