Render RDLC report
To render an RDLC report in the Bold Reports® ASP.NET Web Forms Report Viewer, load the report from the local file system and bind a JSON array or a custom business object data collection as its data source. The following steps demonstrate how to render an RDLC report with a JSON array and a custom business object data collection.
Add the RDLC report
product-list.rdlcfrom Bold Reports® installation location to your applicationResourcesfolder. For more information, see Samples and demos.
How do I bind a data source on the client side?
To bind a data source on the client side of the Web Forms Report Viewer, follow these steps.
-
Set the
ReportPathandReportServiceUrlto 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> -
The following code is used to set the report data source on the 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 configure the Report Viewer Web API controller to render the RDLC report with business object data collection.
-
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; } } -
Set the value of the
ProcessingModeproperty toProcessingMode.Localin the RDLC report location. -
To set the
ReportPathof the report by using theMapPath. -
Bind the business object data values collection by adding a new item to the
DataSourcesas 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
Nameis case sensitive and it should be same as in the data source name in the report definition. TheValueaccepts IList, DataSet, and DataTable inputs.
In the previous code, the
product-list.rdlcreport is loaded from theResourcesfolder location.