【问题标题】:Why won't binding to a child object property with rdlc Report work in vs2010?为什么在 vs2010 中不能使用 rdlc Report 绑定到子对象属性?
【发布时间】:2010-05-18 07:55:36
【问题描述】:

不久前有人问如何在 rdlc 报告中绑定到子对象的属性。问题here

解决方案是使用如下表达式:

=Fields!ChildObject.Value.SomeProperty

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

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

【问题讨论】:

标签: webforms reportviewer rdlc expression reportviewer2008


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    【讨论】:

    • 几个月后,除了展平您的对象之外,MS 仍然没有解决方案。
    • 看起来 VS 2010 SP1 中可能会有修复,非常失望。如果您遇到此问题,请对错误报告进行投票。谢谢!
    【解决方案3】:

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

    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);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      • 2011-06-20
      • 1970-01-01
      • 2012-01-07
      • 2013-04-23
      相关资源
      最近更新 更多