Why does binding to child object with rdlc Report work in vs2010?

Some time ago, someone asked how to bind a property of a child object in a rdlc report. The question is here .

The solution was to use an expression like this:

=Fields!ChildObject.Value.SomeProperty

      

I recently tried to upgrade to version 10 of the reporting libraries (Microsoft.ReportViewer.WebForms and Microsoft.ReportViewer.Common) and for some reason it doesn't work anymore. I have a rendering of a report and displaying all data except those using this technique. Instead of the property value, I get the text: "#Error"

Why doesn't this job work anymore? Does anyone know how to do this in the new version?

+2


a source to share


3 answers


I can confirm that this bug was fixed in VS2010 SP1 ... but you must mark all relevant classes as Serializable.

You can find a sample project on this site that shows a working version: http://wraithnath.blogspot.com/2011/04/reportviewer-object-datasource-nested.html



The author also mentions that your classes will need a parameterless constructor, but I got it to work with classes without a default constructor. However, if you marked everything as serializable and still see the "#Rrror" message, try using parameterless constructors.

+3


a source


0


a source


You really don't need to smooth your objects. Instead, you can link multiple datasets for a report. Then you can assign multiple report data sources to your report by code. Here's a working example:

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

      

Hope this helps someone!

0


a source







All Articles