Crystal Reports Viewer不会超过第2页

Rya*_*yan 15 asp.net crystal-reports

我在aspx页面上有一个Crystal Report Viewer控件,它应该具有内置分页功能.

当我第一次点击"下一页"按钮时,我从第1页移到第2页,但每隔一次我点击"下一页",报告就会重新加载到第2页.

Rya*_*yan 24

问题可能源于ReportSourcePage_Load事件期间设置Crystal Report Viewer控件.这导致每次页面加载都覆盖了页面调度信息,因此当"当前页面"应该为2时,将"当前页面"重新设置为1.

作为一个简单的解决方案,你可以移动将码ReportSourcePage_Init


Spi*_*man 5

手动添加Page_Init()事件并将其连接到InitializeCompnent()中

this.Init += new System.EventHandler(this.Page_Init).
Run Code Online (Sandbox Code Playgroud)

将内容Page_Load移至Page_Init().

if (!IsPostBack)在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;
    }
}
Run Code Online (Sandbox Code Playgroud)