Crystal Report Viewer - ASP.net

时间:2017-03-28 14:15:40

标签: asp.net crystal-reports

我正在尝试将Crystal Report Viewer添加到asp.net Web应用程序中。我们正在使用为我们的桌面应用程序创建的报告,因此它们已经创建并正常运行。我们在两个平台上使用相同的查询连接到同一个数据库,数据库和查询在报表设计器中设置。

以下是asp.net项目中Visual Studio Pro 2015中的一个报告的预览: enter image description here

我已将以下行添加到Reports.aspx页面:

<CR:CrystalReportViewer ID="crptViewer" runat="server" AutoDataBind="true" />

我在应用程序目录的根目录中添加了一个“Crystalreportviewers13”文件夹,其中包含水晶报告安装的内容。

我已将以下内容添加到我的web.config文件中:

<configuration>
  <configSections>
    <sectionGroup name="businessObjects">
      <sectionGroup name="crystalReports">
        <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null"/>
        <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler"/>
      </sectionGroup>
    </sectionGroup>
  </configSections>
   <businessObjects>
    <crystalReports>
      <rptBuildProvider>
        <add embedRptInResource="true"/>
     </rptBuildProvider>
    <crystalReportViewer>
              <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
    </crystalReports>
  </businessObjects>

我已根据不同的堆栈溢出建议尝试了几种策略。这是我到目前为止所尝试的内容:

按钮点击:

public partial class Reports : System.Web.UI.Page

{

ReportDocument rptDocument;
protected void Page_Load(object sender, EventArgs e)
    {
        string stack = "Page_Load()(Reports.aspx.cs)";
        try
        {
            if (Session["report"] != null)
            {
                crptViewer.ReportSource = Session["report"];

            }
        }
        catch (Exception EX)
        {
            IOClass.appendLog("Error in " + stack, EX.Message);
        }
    }

   //Button Click
   protected void generateReport(object sender, EventArgs e)
    {

        rptDocument = new ReportDocument();
        rptDocument.Load(Server.MapPath("~/Crystal/UserListing.rpt"));

        rptDocument.SetParameterValue("Company", 1);

        Session["report"] = rptDocument;


    }
}

和On Load:

public partial class Reports : System.Web.UI.Page
{

    ReportDocument rptDocument;
    protected void Page_Load(object sender, EventArgs e)
    {
        string stack = "Page_Load()(Reports.aspx.cs)";
        try
        {
           rptDocument = new ReportDocument();
           rptDocument.Load(Server.MapPath("~\\Crystal\\UserListing.rpt"));
           crptViewer.ReportSource = rptDocument;

           //I have tried with and without the following:
           //crptViewer.DataBind();
           //and
           //crptViewer.RefreshReport();
        }
        catch (Exception EX)
        {
            IOClass.appendLog("Error in " + stack, EX.Message);
        }
    }
}

当两种情况下加载页面时,这就是我得到的:

enter image description here

我正在对加载函数进行异常日志记录,我没有任何异常。

任何想法我在这里做错了什么?如果我能提供任何其他信息,请告诉我。

感谢您的时间

1 个答案:

答案 0 :(得分:0)

在aspx上删除<div> <label>H:M:S</label><br> <label id="hours">00</label>:<label id="minutes">00</label>:<label id="seconds">00</label> <br> </div> <br> <div> <label>Total Global Footware Revenue per second $</label> <label id="footwareSales"></label><br> <label>Total Footware units sold per second</label> <label id="footwareUnits"></label><br> <label>Total Global Sneakers Revenue per second $</label> <label id="sneakersSales"></label><br> <label >Total sneakers units sold per second </label> <label id="sneakersUnits"></label> </div> 并使用这样的默认html页面...

<asp:Content>

加载aspx.cs

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="myproject.WebForm1" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script type="text/javascript" src="/crystalreportviewers13/js/crviewer/crv.js">
        </script> 
</head>
<body>
    <form id="form1" runat="server">
        <div>
		    <asp:Button ID="btnShowReport" runat="server" Text="Show Report" OnClick="btnShowReport_Click" />
            <CR:CrystalReportViewer ID="JobRepairReportViewer" runat="server" AutoDataBind="true" />
        </div>
    </form>
</body>
</html>