Crystal 报告仅显示第一页

Crystal Report Shows only first page

我正在使用 ASP.NET , SQL , Crystal 报告。我已成功生成单页报告。但是当报告大小超过一页时,Crystal 报告只显示第一页数据。当我单击下一步按钮时,它会显示 "Source empty or No source found" 之类的消息。

  Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim rptDoc As New ReportDocument
    Dim ds As New StudentDataSet
    Dim sqlCon As SqlConnection
    Dim dt As New DataTable
    dt.TableName = "Crystal Report Example"
    sqlCon = New SqlConnection(myCon)
    Dim da As New SqlDataAdapter("select * from tblStudent", sqlCon)
    da.Fill(dt)
    ds.Tables(0).Merge(dt)
    rptDoc.Load(Server.MapPath("~\Reports\StudentList.rpt"))
    rptDoc.SetDataSource(ds)
    CrystalReportViewer1.ReportSource = rptDoc

  End Sub

加载报表的代码必须在每次回发时执行
Page_Init 是放置此代码的正确位置(Page_Load 可能会导致一些错误)。

尝试此更改(抱歉 VB 错误,我使用 C#):

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 ButtonClicked = true
 ShowReport()

Protected void Page_Init(object sender, EventArgs e)
 ShowReport()

Protected Sub ShowReport() 
 Dim rptDoc As New ReportDocument
 Dim ds As New StudentDataSet
 Dim sqlCon As SqlConnection
 Dim dt As New DataTable
 dt.TableName = "Crystal Report Example"
 sqlCon = New SqlConnection(myCon)
 Dim da As New SqlDataAdapter("select * from tblStudent", sqlCon)
 da.Fill(dt)
 ds.Tables(0).Merge(dt)
 rptDoc.Load(Server.MapPath("~\Reports\StudentList.rpt"))
 rptDoc.SetDataSource(ds)
 CrystalReportViewer1.ReportSource = rptDoc

End Sub

嘿,建议在每次卸载页面时关闭 ReportDocument;这避免了将停止应用程序的报告计数器的不受控制的增加

protected void Page_Unload(object sender, EventArgs e)
{
    if (reportDocument != null)
        reportDocument.Close();
}