Search results
PDF

Render RDLC report

The data binding support allows you to view RDLC reports that exist on the local file system with JSON array and custom business object data collection. The following steps demonstrates how to render an RDLC report with JSON array and 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.

Bind data source at client

  1. Set the ReportPath and ReportServiceUrl to the report viewer initialization.

    <div style="height: 650px;width: 950px;min-height:404px;">
        <Bold:ReportViewer runat="server" ID="viewer"
            ReportServiceUrl="/api/ReportViewer"
            ReportPath="~/Resources/product-list.rdlc">
        </Bold:ReportViewer>
    </div>
  2. The following code is used to set the report datasource client side in your application’s Page_Load() function.

    protected void Page_Load(object sender, EventArgs e)
    {
        ProductList productList = new ProductList();
        List<BoldReports.Models.ReportViewer.ReportDataSource> dataSources = new List<BoldReports.Models.ReportViewer.ReportDataSource>();
        BoldReports.Models.ReportViewer.ReportDataSource dataSource = new BoldReports.Models.ReportViewer.ReportDataSource();
        dataSource.Name = "list";
        dataSource.Value = productList.GetData();
        dataSources.Add(dataSource);
        this.viewer.DataSources = dataSources;
    }

Bind data source in Web API controller

The following steps help you to configure the Web API to render the RDLC report with business object data collection.

  1. Create a class and methods that returns business object data collection. Use the following code in your application Web API Service.

    [Serializable]
    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;
        }
    }
  2. Set the value of the ProcessingMode property to ProcessingMode.Local in the RDLC report location.

  3. To set the ReportPath of the report by using the MapPath.

  4. Bind the business object data values collection by adding a new item to the DataSources as in the following code snippet.

    [NonAction]
    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
        reportOption.ReportModel.ReportPath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/Resources/product-list.rdlc");
        reportOption.ReportModel.DataSources.Add(new BoldReports.Web.ReportDataSource { Name = "list", Value = ProductList.GetData() });
    }

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

In the previous code, the product-list.rdlc report is loaded from the Resources folder location.