【问题标题】:Crystal Report Shows only first pageCrystal Report 仅显示第一页
【发布时间】:2015-01-13 06:24:01
【问题描述】:

我正在使用 ASP.NET、SQL、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

【问题讨论】:

  • 你看,对于大多数人来说,这不会发生。而且您尚未发布任何使您的案例与大多数人不同的详细信息,这意味着您的问题中没有可供人们用来回答问题的信息。发布源代码或其他详细信息,以便这里的人们有所了解。
  • 确切的消息框是“没有可用的有效报告源”。我还不能发布图片。它显示,当我点击水晶报表的下一页按钮时。

标签: asp.net crystal-reports-2010


【解决方案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();
}

【讨论】:

  • 谢谢,但现在它显示加载报告,没有按钮单击。另外,请解释 ButtonClicked = true 的用途。和你一样,我只是一个 VB 开发人员
  • 工作:我没有将 ShowReport() 放在 Page_Init 中,而是使用 If Page.IsPostBack Then Report() End If 将它放在 Page_Load 中
  • 我使用了一个名为 ButtonClicked 的布尔变量,它在按钮单击时设置,以避免这个问题
  • 您也可以在关闭报表后进行dispose。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
  • 2012-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多