views:

745

answers:

2

Situation: We've designed a decent looking Report page using the .NET ReportViewer (ASP.NET, RDLC) with a custom object from our object model. My underlying (and possibly incorrect) assumption was that if we bound a collection of custom objects to the ReportViewer/RDLC, the control would build a populated report layout for each object in the collection.

My past report experience has been with the MS-Access report engine, where binding a datasource to a report will result in the report layout being applied for each record in the data source. If the report layout spanned an entire page, for example, a populated report page would be built for each bound record.

Question: My colleague tells me that the .NET ReportViewer cannot function in the way I describe. Really? Please tell me he is mistaken? Any guidance on a solution or work-around?

Thanks in advance, -JR

NOTE: Original question title changed in response to clarifying answer.

A: 

You should be able to find your solution here: http://www.gotreportviewer.com/

more here on binding custom classes/collections http://www.gotreportviewer.com/objectdatasources/index.html

I don't think rdlc creates layouts for you.

darthjit
+3  A: 

The short answer: Yes. The ReportViewer can behave in the manner you describe. (Your colleague is incorrect.)

There are a couple approaches for displaying all rows in your data source rather than just the first one. I'm most familiar with the List Control approach which is described here but there is also a Master-Detail approach using either subreports or nested data regions.

Strictly speaking, this question is about displaying multiple data rows, not custom object collections. You might want to edit the question title from, “.NET ReportViewer capabilities: Binding to custom object collections?” to say “.NET ReportViewer capabilities: Displaying multiple rows”?

When designing your report, if you place a field from your data source onto the report designer and display the report, you've noticed only one row is displayed rather than the whole dataset. On closer inspection, the ReportDesigner wrapped the aggregate function First() around your data field. This is the default behavior for the ReportViewer.

What you want to do is use the List control and place your data field control(s) within it. Now, all field rows will be displayed. It is that easy.

The List is a critical component in successful use of the ReportViewer. Read up on it. The List can accommodate greater complexity using its Group Expression capabilities and also by nesting List/Table controls within it.

Resources:

As mentioned in another post, one of the best web resources for the ReportViewer is the GotReportViewer site. There you'll find more info on using List, Master-Detail and more.

Good luck.

Ed Lee