Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal Reports Viewer won't go past page 2

I have a Crystal Report Viewer control on an aspx page, which is supposed to have built-in paging.

When I click the "next page" button the first time, I move from page 1 to page 2, but every other time I click "next page" the report reloads to page 2.

like image 561
Ryan Avatar asked Aug 27 '09 19:08

Ryan


2 Answers

The problem may stem from setting the Crystal Report Viewer control's ReportSource during the Page_Load event. This causes the paging information to be over-written with each page load, so the "current page" is re-set to 1 when it should be at 2.

As an easy solution, you can move the code that sets ReportSource into Page_Init

like image 105
Ryan Avatar answered Oct 25 '22 08:10

Ryan


Manually add the Page_Init() event and wire it up in the InitializeCompnent() with

this.Init += new System.EventHandler(this.Page_Init).

Move the contents of Page_Load to Page_Init().

Add if (!IsPostBack) condition in PageInIt.

protected void Page_Init(object sender, EventArgs e) {

    if (!IsPostBack)
    {
         ReportDocument crystalReportDocument = new ReportDocumment();
         crystalReportDocument.SetDataSource(DataTableHere);
         _reportViewer.ReportSource = crystalReportDocument;
         Session["ReportDocument"] = crystalReportDocument;
    }
    else
    {
          ReportDocument doc = (ReportDocument)Session["ReportDocument"];
          _reportViewer.ReportSource = doc;
    }
}
like image 30
Spider man Avatar answered Oct 25 '22 06:10

Spider man