Render subreport
To render a subreport in the Bold Reports® UWP Report Viewer, add the main report and subreport to your application and set the report path and service URL. A subreport displays another report inside the body of the main report. The following steps help you customize the subreport properties such as data source, report path, and parameters.
-
Add the sub report and main reports to your application
Resourcesfolder. In this tutorial, using the already created reports. Refer to the Create RDL report or Create RDLC report section to create new reports.Download the
side-by-side-main-report.rdl,side-by-side-sub-report.rdlreports from the subreport sample reports download. You can also add the reports from the Bold Reports® installation location. For more information, see Samples and demos. The reports used from installed location, requiresNorthwindIO_Reports.sdfdatabase to run, so add it to your application. -
Set the main report path
ReportPathandReportServiceURLproperties of the Report Viewer as in following code snippet.
this.ReportViewer.ReportServiceURL = @"https://demos.boldreports.com/services/api/ReportViewer";
this.ReportViewer.ReportPath = "~/Resources/docs/side-by-side-main-report.rdl";
this.ReportViewer.RefreshReport();How do I load a subreport as a stream?
To load a subreport as a stream in the UWP Report Viewer, set the subreport stream in the LoadSubreport() method as in the following code snippet:
Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
Stream mainReportStream = assembly.GetManifestResourceStream("ReportViewer_UWP.Resources.product-list-main.rdlc");
Stream subReportStream = assembly.GetManifestResourceStream("ReportViewer_UWP.Resources.product-list.rdlc");
this.ReportViewer.ProcessingMode = BoldReports.UI.Xaml.ProcessingMode.Local;
this.ReportViewer.SubreportProcessing += (sen, arg) =>
{
arg.DataSources.Clear();
arg.DataSources.Add(new BoldReports.UI.Xaml.ReportDataSource { Name = "list", Value = ProductList.GetData() });
};
this.ReportViewer.LoadSubreport("product-list", subReportStream);
this.ReportViewer.LoadReport(mainReportStream);
this.ReportViewer.RefreshReport();
.....
public class ProductList
{
public string ProductName { get; set; }
public string OrderId { get; set; }
public double Price { get; set; }
public string Category { get; set; }
public string Ingredients { get; set; }
public string ProductImage { get; set; }
public static IList GetData()
{
List<ProductList> datas = new List<ProductList>();
ProductList data = null;
data = new ProductList()
{
ProductName = "Baked Chicken and Cheese",
OrderId = "323B60",
Price = 55,
Category = "Non-Veg",
Ingredients = "grilled chicken, corn and olives.",
ProductImage = ""
};
datas.Add(data);
data = new ProductList()
{
ProductName = "Chicken Delite",
OrderId = "323B61",
Price = 100,
Category = "Non-Veg",
Ingredients = "cheese, chicken chunks, onions & pineapple chunks.",
ProductImage = ""
};
datas.Add(data);
data = new ProductList()
{
ProductName = "Chicken Tikka",
OrderId = "323B62",
Price = 64,
Category = "Non-Veg",
Ingredients = "onions, grilled chicken, chicken salami & tomatoes.",
ProductImage = ""
};
datas.Add(data);
return datas;
}
}