1

我很难使用reportviewer 让子报告显示在我的应用程序中。它在本地调试时完美运行。但是当我将它上传到服务器时,子报告是空白的。

我相信 SubreportProcessing 事件没有触发,因为我没有看到 SQL Server Profiler 触发了存储过程。这是我正在使用的代码。

private void RunReport(string strFormat, int PlanID)
    {
        const string reportrdlc = "Reports\\Report_All_Sections.rdlc";
        LocalReport report = new LocalReport {ReportPath = Server.MapPath(reportrdlc)};
        report.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));
        report.DataSources.Clear();
        report.SubreportProcessing += SetSubDataSource;

        report.DataSources.Add(new ReportDataSource("DataSet_usp_GetSD", _wpt.Get_SD(PlanID).Copy()));

        report.Refresh();

        string mimeType;
        string encoding;
        string fileNameExtension;
        string[] streams;
        Warning[] warnings;

        byte[] pdfContent = report.Render(strFormat, null, out mimeType, out encoding,
                    out fileNameExtension, out streams, out warnings);

        System.IO.MemoryStream stream = new System.IO.MemoryStream(pdfContent);
        Response.ContentType = strFormat == "EXCEL" ? "application/vnd.ms-excel" : "application/pdf";

        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        Response.Close();
        stream.Close();

    }
    public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
    {
        int PlanID = 1;
        if (Request.QueryString["PlanID"] != null)
        {
            try
            {
                PlanID = Convert.ToInt32(Request.QueryString["PlanID"]);
            }
            catch (Exception Ex)
            {
                PlanID = 1;
            }
        }
        switch (e.ReportPath)
        {
            case "Report_All_Mentor":
                e.DataSources.Add(new ReportDataSource("DataSet_usp_GetMC", _wpt.Get_MC(PlanID).Copy()));
                break;
            case "Report_All_Intern":
                e.DataSources.Add(new ReportDataSource("DataSet_usp_GetEA", _wpt.Get_EA(PlanID).Copy()));
                break;
        }


    }
4

1 回答 1

1

我似乎有同样的问题。我认为问题在于,当部署 reportPath 时包含报告的完整路径,但是当您在本地调试时,它只传递报告名称。

是否有可能您的 SubreportProcessing 事件确实正在触发,但在您的 switch 语句中,没有一个案例与 reportPath 参数中包含的完整路径匹配。

我不知道如何解决这个问题,但我认为这可能是根本原因。

于 2014-02-17T11:22:43.923 回答