Search results
Suggest a FeaturePDF

Render subreport

You can display another report inside the body of a main report using the Report Viewer. The following steps helps you to customize the subreport properties such as data source, report path, and parameters.

  • Add the sub report and main reports to your application Resources folder. In this tutorial, using the already created reports. Refer to the Create RDL Report section or Create RDLC Report section section for creating new reports.

    Download the side-by-side-main-report.rdl, side-by-side-sub-report.rdl reports from here. Also, you can add the report from Syncfusion® installation location. For more information, see Samples and demos. The reports used from installed location, requires NorthwindIO_Reports.sdf database to run, so add it to your application.

  • Set the main report path ReportPath properties of the Report Viewer as in following code snippet.

this.reportViewer.ReportPath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\side-by-side-main-report.rdl");
this.reportViewer.RefreshReport();

Load subreport stream

To load subreport as stream, set the sub report stream in LoadSubreport method of the Report Viewer as in following code snippet.

FileStream subReportStream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\product-list.rdlc"), FileMode.Open, FileAccess.Read);
FileStream mainReportStream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\product-list-main.rdlc"), FileMode.Open, FileAccess.Read);
this.reportViewer.SubreportProcessing += (sen, arg) =>
{
    arg.DataSources.Clear();
    arg.DataSources.Add(new BoldReports.Windows.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;
    }
}
Having trouble getting help?
Contact Support
Having trouble getting help?
Contact Support