Search results
PDF

Render RDLC report

The data binding support, allows you to view RDLC reports that exist on the custom business object data collection. The following steps demonstrates how to render a RDLC report with custom business object data collection.

Add the RDLC report product-list.rdlc from Bold Reports installation location to your application Resources folder. For more information, see Samples and demos.

  • Set the ReportPath and ProcessingMode to ProcessingMode.Local to the RDLC report location.
  • Bind the business object data values collection by adding new item to the DataSources as in the following code snippet.
    this.reportViewer.ReportPath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\product-list.rdlc");
    this.reportViewer.ProcessingMode = BoldReports.UI.Xaml.ProcessingMode.Local;
    this.reportViewer.DataSources.Clear();
    this.reportViewer.DataSources.Add(new BoldReports.Windows.ReportDataSource { Name = "list", Value = ProductList.GetData() });
    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;
    }
}

Load report as stream

To load report as a stream, create a report stream using the FileStream class and assign the report stream to the Stream property.

FileStream reportStream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\product-list.rdlc"), FileMode.Open, FileAccess.Read);
this.reportViewer.ProcessingMode = BoldReports.UI.Xaml.ProcessingMode.Local;
this.reportViewer.LoadReport(reportStream);
this.reportViewer.DataSources.Clear();
this.reportViewer.DataSources.Add(new BoldReports.Windows.ReportDataSource { Name = "list", Value = ProductList.GetData() });
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;
    }
}