Articles in this section
Category / Section

How to bind business object data collection in a report?

Published:
Updated:

The section explains how to bind business object data collection to a report through the client and server side for RDLC reports.

Bind data source at client side

  1. Set the RDLC report path to the reportPath property.
  2. Assign the processingMode property to Local.
  3. Bind the JSON array collection to the dataSources property as shown in the following code.
<script type="text/javascript">
        $(function () {
            $("#viewer").boldReportViewer({
                reportServiceUrl: "/api/ReportViewer",
                processingMode: ej.ReportViewer.ProcessingMode.Local,
                reportPath: '~/Resources/docs/product-list.rdlc',
                dataSources: [{
                    value: [
                    {
                        ProductName: "Baked Chicken and Cheese", OrderId: "323B60", Price: 55, Category: "Non-Veg", Ingredients: "Grilled chicken, Corn and Olives.", ProductImage: ""
                    },
                    {
                        ProductName: "Chicken Delite", OrderId: "323B61", Price: 100, Category: "Non-Veg", Ingredients: "Cheese, Chicken chunks, Onions & Pineapple chunks.", ProductImage: ""
                    },
                    {
                        ProductName: "Chicken Tikka", OrderId: "323B62", Price: 64, Category: "Non-Veg", Ingredients: "Onions, Grilled chicken, Chicken salami & Tomatoes.", ProductImage: ""
                    }],
                    name: "list"
                }]
            });
        });
</script>

Bind data source at server side (Web API Controller)

  • You need to create a class and methods that return business object data collection, as shown in the following example.
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;
    }
}
  • You need to bind the business object data values collection to the Report Viewer using the DataSources property in the following code snippet.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
reportOption.ReportModel.DataSources.Add(new BoldReports.Web.ReportDataSource { Name = "list", Value = ProductList.GetData() });
}

Here, the Name is case sensitive and it should be the same as in the data source name in the report definition. The Value accepts IList, DataSet, and DataTable inputs.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied