Crystal Report仅显示第一页

时间:2015-01-13 06:24:02

标签: asp.net crystal-reports-2010

我正在使用ASP.NET,SQL,Crystal Report。我已成功生成单页报告。但是,当报表大小超过一页时,Crystal Report仅显示第一页数据。当我点击下一个按钮时,它显示"来源为空或没有找到来源"喜欢消息。

  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

enter image description here

1 个答案:

答案 0 :(得分:1)

加载报告的代码必须在每次回发时执行 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();
}