Passing Values to Report Parameters from Components Outside the HTML5 WebForms Report Viewer
This topic explains how to use custom parameters UI to update the report parameters instead of using the HTML5 Web Forms report viewer's default implementation of the parameters area. The report and all required parameters for it are packed in a ReportSource object. To update the report source the ReportViewer.reportSource(rs) method is used.
To give an example we will use the Invoice report from our examples and will update its OrderNumber parameter from a custom parameter UI.
Pass values to report parameters
All path references in the described steps should be adapted according to your project setup. For more information please refer to the Microsoft article ASP.NET Web Project Paths
- Create a new ASP.NET Web Forms Empty Project. We are going to use one of our demo Visual Studio reports. For this purpose add a new Telrik Report Library project to the solution from the VS item templates, name it Charp|VB.ReportLibrary, add the existing Invoice.cs report and its subreport SalesOrderDetails.cs from [TelerikReporting_InstallDir]\Examples\CSharp|VB\ReportLibrary\Invoice folder and built the Charp|VB.ReportLibrary project. Add reference to the ReportLibrary project in the Web Forms project.
- Then use the HTML5 Web Forms Report Viewer Item Template and name the web page with the viewer InvoiceParameters.aspx. On 'Configure report source' step select 'Existing report definition', then select 'Select type report definition created in Visual Studio' and browse Invoice report class. Finish the wizard.
-
Add a connectiongStrings entry with name Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString in the project's
web.config
file. For example:At this point you have a running Web Forms application that displays a report in the HTML5 Web Forms Viewer at [host]/InvoiceParameters.aspx without any modifications.
-
Add code for updating ReportSource Parameters collection in the code behind:
-
Add the report viewer stylesheet:
-
Add the custom parameter UI - a dropdown selector with a few values:
-
Now initialize the report viewer. We will use the minimal set of all possible options.
-
Add code that updates the ReportSource parameters collection with the selected Invoice Id from the dropdown box:
-
The HTML page that we have just created should looks like this:
Run the project and verify that the Invoice Id selection really updates the report.