.RDLC Report 2008(在 VS 2010 中)ReportViewer 显示没有报告或数据
在 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,这篇博客文章回答了。简短的回答是我需要安装可再发行的报告查看器,并添加处理程序。
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.
报告内容似乎已呈现,但根本不可见。
尝试使用 Chrome 查看生成的 HTML (DOM)
也许一些过去有效的 CSS 现在隐藏了您的报告区域。
It seems like the report content gets rendered but is simply not visible.
Try to look at the generated HTML (DOM) with
Maybe some CSS that has worked in the past now hides your report area.