.RDLC Report 2008(在 VS 2010 中)ReportViewer 显示没有报告或数据

发布于 2024-11-14 05:28:51 字数 2897 浏览 2 评论 0原文

在 VS 2008 中使用 .RDLC 2005,这种技术效果非常好,现在在 VS 2010 中实现的 .RDLC 2008 中,我得到了一个空白(或没有?)的报告。

我做了一些更改以适应 .RDLC 2008,目前我没有例外。当前(不需要)的输出如下所示: 在此处输入图像描述

我有一个自定义 ReportController 类,它具有 ShowReport 的公共方法(也是管理报告导出的方法) ,但这还没有发挥作用。)

从 asp.net 页面,我调用属性集中的控制器(类型为 DataSet,由页面控制器调用),如下所示:(ReportController 实现 IDisposable

try
{
    using (var reportController = new ReportController(true))
    {
         _ReportViewer = reportController.ShowReport("DemonstrationList", value, phReportHolder);

         if (_ReportViewer != null)
         {
             _ReportViewer.ShowRefreshButton = false;
             _ReportViewer.ShowPrintButton = false;
             _ReportViewer.Width = Unit.Pixel(700);// Unit.Percentage(99);
             _ReportViewer.Height = Unit.Pixel(700);// Unit.Percentage(90);
         }
    }

    lblRecordCount.InnerText = value.Tables[0].Rows.Count.ToString();
}
catch (Exception ex)
{
    phReportHolder.InnerHtml = string.Format("There was an error attempting to process this report <br/><br/><div style='color:White;'>{0}</div>", ex.Message);
}

并且 ShowReport 方法是:

public ReportViewer ShowReport(string ReportName, DataSet ds, HtmlContainerControl ReportContainer)
{
    ReportContainer.Controls.Clear();
    ReportViewer reportViewer = BuildReport(ReportName, ds);
    ReportContainer.Controls.Add(reportViewer);
    return reportViewer;
}

这允许我告诉控制器使用任何提供的数据集将任何“有效”报告放入任何 htmlcontainercontrol 中。

BuildReport 获取数据和报告名称并将报告构建为:

private ReportViewer BuildReport(string ReportName, DataSet ds)
{
      try
      {
         _activeDS = ds;
         string ReportFileName = ResolveRDLCName(ReportName);
             // ResolveRDLCName is used along with path strings 
             // initialized from configuration settings in the 
             // constructor to make this portable. 
         var viewer = new ReportViewer();
         viewer.ProcessingMode = ProcessingMode.Local;
         viewer.LocalReport.ReportPath = ReportFileName;
         viewer.LocalReport.DisplayName = ReportName;
         viewer.LocalReport.EnableHyperlinks = true;
         AssignReportData(ds, viewer.LocalReport);

        return viewer;
      }
      //...Exception handlers below are not invoked at this time

并且“AssignReportData”将数据附加到报告。

private static void AssignReportData(DataSet ds,  LocalReport Report)
{
         var listOfDatasources = Report.GetDataSourceNames();

         foreach (string dsn in listOfDatasources)
         {
            ReportDataSource rds = new ReportDataSource(dsn,ds.Tables[dsn]);
            Report.DataSources.Add(rds);
         }
}

开发技术确保数据表/数据源名称保持一致(如果不一致,我会得到一个特定的异常,但我没有。)

Working with .RDLC 2005 in VS 2008 this technique worked very well, now in .RDLC 2008 as implemented in VS 2010 I get a blank (or no?) report.

I have made a couple of changes to accommodate .RDLC 2008 and at this time I am getting no exceptions. The present (not desired) output looks like:
enter image description here

I have a custom ReportController class that has a public method to ShowReport (also one to manage the exporting of reports, but that is not (yet) in play.)

From the asp.net page I invoke the controller in the property set (of Type DataSet, invoked by the page controller) like: (ReportController implements IDisposable)

try
{
    using (var reportController = new ReportController(true))
    {
         _ReportViewer = reportController.ShowReport("DemonstrationList", value, phReportHolder);

         if (_ReportViewer != null)
         {
             _ReportViewer.ShowRefreshButton = false;
             _ReportViewer.ShowPrintButton = false;
             _ReportViewer.Width = Unit.Pixel(700);// Unit.Percentage(99);
             _ReportViewer.Height = Unit.Pixel(700);// Unit.Percentage(90);
         }
    }

    lblRecordCount.InnerText = value.Tables[0].Rows.Count.ToString();
}
catch (Exception ex)
{
    phReportHolder.InnerHtml = string.Format("There was an error attempting to process this report <br/><br/><div style='color:White;'>{0}</div>", ex.Message);
}

and the ShowReport method is:

public ReportViewer ShowReport(string ReportName, DataSet ds, HtmlContainerControl ReportContainer)
{
    ReportContainer.Controls.Clear();
    ReportViewer reportViewer = BuildReport(ReportName, ds);
    ReportContainer.Controls.Add(reportViewer);
    return reportViewer;
}

This allows me to tell the controller to put any 'valid' report into any htmlcontainercontrol using any provided dataset.

BuildReport takes the data and the report name and builds the report as:

private ReportViewer BuildReport(string ReportName, DataSet ds)
{
      try
      {
         _activeDS = ds;
         string ReportFileName = ResolveRDLCName(ReportName);
             // ResolveRDLCName is used along with path strings 
             // initialized from configuration settings in the 
             // constructor to make this portable. 
         var viewer = new ReportViewer();
         viewer.ProcessingMode = ProcessingMode.Local;
         viewer.LocalReport.ReportPath = ReportFileName;
         viewer.LocalReport.DisplayName = ReportName;
         viewer.LocalReport.EnableHyperlinks = true;
         AssignReportData(ds, viewer.LocalReport);

        return viewer;
      }
      //...Exception handlers below are not invoked at this time

And 'AssignReportData' attaches the data to the report.

private static void AssignReportData(DataSet ds,  LocalReport Report)
{
         var listOfDatasources = Report.GetDataSourceNames();

         foreach (string dsn in listOfDatasources)
         {
            ReportDataSource rds = new ReportDataSource(dsn,ds.Tables[dsn]);
            Report.DataSources.Add(rds);
         }
}

Development techniques ensure that dataTable/dataSource names stay in agreement (and if they were not I would get a specific exception, which I do not.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒解孤独 2024-11-21 05:28:51

我遇到了类似的问题,这篇博客文章回答了。简短的回答是我需要安装可再发行的报告查看器,并添加处理程序。

I was having a similar problem which this blog post answered. Short answer is I needed to install the report viewer redistributable, and add the handler.

陌生 2024-11-21 05:28:51

报告内容似乎已呈现,但根本不可见。

尝试使用 Chrome 查看生成的 HTML (DOM)

  • :右键单击报告区域,“检查元素”以探索 DOM
  • Internet Explorer:安装 IE 开发工具栏 用于探索 DOM

也许一些过去有效的 CSS 现在隐藏了您的报告区域。

It seems like the report content gets rendered but is simply not visible.

Try to look at the generated HTML (DOM) with

  • Chrome: right-click on the report area, "Inspect Element" to explore the DOM
  • Internet Explorer: install the IE Developer Toolbar to explore the DOM

Maybe some CSS that has worked in the past now hides your report area.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文