2

前段时间有人问如何在 rdlc 报告中绑定到子对象的属性。问题在这里

解决方案是使用这样的表达式:

=Fields!ChildObject.Value.SomeProperty

我最近尝试升级到版本 10 的报告库(Microsoft.ReportViewer.WebForms 和 Microsoft.ReportViewer.Common),但由于某种原因这不再起作用。除了使用这种技术的任何数据外,我已经得到了报告渲染和显示所有数据。我得到的不是属性值,而是文本:“#Error”

为什么这不再起作用了?有人知道如何在新版本中做到这一点吗?

4

3 回答 3

3

我可以确认此错误已在 VS2010 SP1 中修复......但您必须将所有相关类标记为可序列化。

您可以在此站点上找到一个显示工作版本的示例项目: http ://wraithnath.blogspot.com/2011/04/reportviewer-object-datasource-nested.html

作者还提到您的类将需要一个无参数构造函数,但我已经让它与没有默认构造函数的类一起工作。尽管如此,如果您已将所有内容标记为可序列化并且仍然看到“#Error”消息,请尝试使用无参数构造函数。

于 2011-10-16T02:31:53.290 回答
0

你真的不必扁平化你的对象。相反,您可以将多个数据集绑定到报告中。然后您可以通过代码将多个报表数据源分配给您的报表。这是工作示例:

List<Loan> loans = new List<Loan>();
loans.Add(GetLoanByLoanNumber(loanNumber));

LocalReport report = new LocalReport();
report.ReportPath = HostingEnvironment.MapPath("~/bin/Report/Receipt.rdlc");

ReportDataSource loanDetailsDataSource = new ReportDataSource();
loanDetailsDataSource.Name = "LoanDataSet"; //This refers to the dataset name in the RDLC file
loanDetailsDataSource.Value = loans;
report.DataSources.Add(loanDetailsDataSource);

ReportDataSource loanItemsDataSource = new ReportDataSource();
loanItemsDataSource.Name = "LoanItemsDataSet"; //This refers to the dataset name in the RDLC file  
loanItemsDataSource.Value = loans[0].loanItems;
report.DataSources.Add(loanItemsDataSource);

ReportDataSource principalPaymentDataSource = new ReportDataSource();
principalPaymentDataSource.Name = "PrincipalPaymentDataSet"; //This refers to the dataset name in the RDLC file
principalPaymentDataSource.Value = loans[0].principalPayments;
report.DataSources.Add(principalPaymentDataSource);

ReportDataSource interestPaymentDataSource = new ReportDataSource();
interestPaymentDataSource.Name = "InterestPaymentDataSet"; //This refers to the dataset name in the RDLC file  
interestPaymentDataSource.Value = loans[0].interestPayments;
report.DataSources.Add(interestPaymentDataSource);

希望这会对某人有所帮助!

于 2017-07-25T20:07:48.200 回答