If you want each employee’s data to appear on a separate page in your RDLC report, you don’t actually need to generate multiple reports in a loop. Instead, you can use grouping and page breaks in your RDLC design, and just pass all your data at once. Here’s how you can do it:
1. Group Your Data in the RDLC Report
- In the RDLC designer, add a table or list.
- Right-click the row handle (on the left) and choose “Add Group” → “Parent Group…”.
- Set the group expression to
=Fields!empid.Value
. - In the group properties, go to the
Page Breaks
section and checkBetween each instance of a group
. This will force a new page for each empid.
2. Pass All Data to the Report
- You don’t need to filter by empid in your C# code. Just pass the entire list of orders to the report’s datasource.
3. Sample C# Code
public IActionResult testPrint()
{
List<tbl_order> orders = new List<tbl_order>()
{
// ... your sample data ...
};
// No need to filter or group in C#; let RDLC handle it
string path = _webHostEnvironment.WebRootPath + @"\Reports\xyz.rdlc";
LocalReport localreport = new LocalReport(path);
localreport.AddDataSource("DataSet1", orders);
// If you want to pass parameters, you can, but not needed for grouping
var report = localreport.Execute(RenderType.Pdf, 1, null, "");
return File(report.MainStream, "application/pdf");
}
4. Result
- When you run the report, each employee’s data will start on a new page, thanks to the group and page break settings in the RDLC file.