0

If I assign a collection of objects to a ReportViewer's DataSource, how can I view one report page per object?

Let's say I have code like this that sets ReportViewer's DataSource:

var invoice1 = new Invoice() { InvoiceNbr = 1 };
var invoice2 = new Invoice() { InvoiceNbr = 2 };

InvoiceBindingSource.DataSource = new List<Invoice>() { invoice1, invoice2 };
reportViewer1.RefreshReport();

Assume reportViewer1 is bound to a very simple RDLC report bound to my Invoice custom class. The report has a single textbox bound to the InvoiceNbr property.

My problem: If I run this code, ReportViewer only shows 1 page, not two. Only InvoiceNbr 1 is shown.

Thoughts: If I execute this code, the report's textbox bound to the InvoiceNbr property must be an aggregate value, like =First(Fields!InvoiceNbr.Value, "InvoiceGraphDataset") ---note: if I instead use Fields!InvoiceNbr.Value, I get a design-time error stating the value must be an aggregate expression.

My question reiterated: So, how do I get two report pages in my ReportViewer showing InvoiceNbr 1 on a page and InvoiceNbr 2 on a different page? I can do this easily in MS Access.

Edit: I'm terrified this is the only answer. Can someone confirm there's a better way than creating a table-row w/ page breaks report? It seems like there should be a more intuitive way to make one report page per Invoice object. Help?

Community
  • 1
  • 1
David Alan Condit
  • 1,243
  • 11
  • 20

1 Answers1

0

There are two ways to achieve this:

  • use one column Table control, drop your text box in detail cell, add group by your InvoiceNbr field (without group header and footer) and adjust group properties to print each group on new page

  • use List control, drop you textbox in List body and do the same steps as in option above.

I don't see anything un-intuitive in these two approaches, the bottom line - you need something in your report that would recognize that this is time to create new page, something bound to your datasource with the criteria for page change.

InitK
  • 1,261
  • 13
  • 21
  • Thanks for your suggestions. I'll try them out this week. If it matters, my report is more complicated than a single textbox - it has many textboxes, lines, rectangles, a table, a header, and a footer. I dumbed down my example since I feel the principle I'm after is 1 "view" (report) per 1 object (Invoice). – David Alan Condit Mar 14 '16 at 22:00