How to make ReportViewer display multiple pages (e.g. one page per DataRow)?
Ok, I figured this out:
- Add a List element to the report and stretch it to fill report body.
- Link the Tablix of this List element to my DataSet.
- Add a TextBox element inside List element.
- Select the expression for TextBox element: =Fields!CustomerCode.Value
- Right-click outside report body and select View -> Grouping.
- Add a Row Group.
- In Row Group properties General -> add grouping on CustomerCode field.
- In Row Group properties Page Breaks -> select Page break options -> Between each instance of a group.
- If report always generates an extra page with empty fields - open the .rdlc file in XML viewer, find page break tag and remove it.
Pretty obvious, isn't it?
Related videos on Youtube
ttaaoossuuuu
Updated on September 16, 2022Comments
-
ttaaoossuuuu over 1 year
I'm new to MS reporting. What I'm trying to achieve is to make a simple report which would be filled from a
DataTable
(made programmatically). The idea is to assing data for each page to values fromDataRow
. I.e. report page1
would get itsTextBox
values fromDataTable.Rows[0]
, report page2
would display values fromDataTable.Rows[1]
etc. Number of pages = number ofDataRows
.I've coded a WinForms app that gets a
DataTable
from SQL and filters it based on parameters supplied by user and then displays a Report.Then I created an empty dummy
DataSet
calledComplianceFormDataSet
which contains all the field names I will need further. Then I made an.rdlc
, added aTextBox
to it with this expression:=Fields!CustomerCode.Value
Here's the logic behind passing the data to ReportViewer:
DataTable MainDataTable = new DataTable(); MainDataTable.Columns.Add("CustomerCode", typeof(string)); MainDataTable.Rows.Add("Blah1"); MainDataTable.Rows.Add("Blah2"); ReportDataSource MainDataSource = new ReportDataSource("ComplianceFormDataSet", MainDataTable); MainReportViewer.LocalReport.DataSources.Clear(); MainReportViewer.LocalReport.DataSources.Add(MainDataSource); MainReportViewer.RefreshReport();
When I build this a get a report with one page saying
"Blah1"
. How do I make it render two pages: one with"Blah1"
and the second with"Blah2"
? Thank you. -
Smith over 7 yearswhich visual studio is this, as this does not follow for vs2008