以集合作为数据源的 Microsoft 报告
我正在使用 MS Reporting Services。底层数据源是
IEnumerable
每个MyObject
都有属性和一些其他IEnumerable
集合。 在报告中,我想显示 MyObject
中的所有属性和 收藏品列表也有。 我不知道如何显示这个内部集合,所以我制作了一个 SubReport ,向其中传递了 MyObject
.Id ,以便 SubReport 可以通过以下方式检索对象:他自己并为这些内部集合构建一个数据源。 我在这次活动中这样做。
myReportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
int id;
if (e.Parameters.Count > 0 && int.TryParse(e.Parameters[0].Values[0], out id))
{
MyObject current = myObjects.Where(x => x.MyObject.Id == id).FirstOrDefault();
InnerListBindingSource.DataSource = current.InnerCollection;
e.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource(
"MyInnerCollectionDataSource", InnerListBindingSource));
}
}
但我的主报告中总是出现“子报告无法显示”。 (主报告 - 子报告已正确绑定)
知道为什么吗?或者如何以更优雅的方式解决这个问题?
谢谢
I'm working with MS Reporting Services. The underlying datasource is
IEnumerable<MyObject>
, I'm not using DataSets.
Every MyObject
has properties and some other IEnumerable
collections.
In the report I want to display all the properties from MyObject
and
the collections lists too.
I didn't know how to display this inner collections, so I've made a SubReport to which I passed the MyObject
.Id so that the SubReport could retrieve the object by himself and Build a the DataSource for these inner collections.
I do this in this event.
myReportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
int id;
if (e.Parameters.Count > 0 && int.TryParse(e.Parameters[0].Values[0], out id))
{
MyObject current = myObjects.Where(x => x.MyObject.Id == id).FirstOrDefault();
InnerListBindingSource.DataSource = current.InnerCollection;
e.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource(
"MyInnerCollectionDataSource", InnerListBindingSource));
}
}
But there is always "The SubReport could not be shown" in my Master Report.
(Master report - subreport are correctly binded)
Any Idea why? Or how to resolve this in a more elegant way ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的。
所以我去了这个解决方案并且它正在工作:
OK.
So I went to this solution and it's working:
如果我理解正确的话,你有一个类似于表格的结构。那你为什么不拿一个DataTable呢? ReportingServices 可以轻松访问这些内容。
还是我误会你了?
If I understand you correctly, you have a structure that resembles a table. So why don't you take a DataTable? ReportingServices offers easy access to those.
Or did I get you wrong there?