How to pass parameter into report through URL
Working with reports on the Internet, there is a need to transmit the values of any parameters. This, for example, can be data for filtering lists or customer information. It would be convenient to pass parameters using the URL (Universal Resource Locator) when you call the web form with the report. It is quite easy to do this.
Let's consider the simplest example. In the report template, there are two parameters: Param1 and Param2 of type string:
You need to pass the values for these parameters using the URL.
Create a web application ASP.Net WebForms. We place a WebReport component on a page. Add the created report template to the project. Right-click on the folder App_Data and select «Add-> Existing Item ...». Then we find the report file on the hard disk. Now go to the C # code page. First of all, we add libraries:
I used the Load page event, because at this stage the report is not yet displayed:
Note that the parameter name exactly matches the parameter name in the report template:
The URL looks like this:
The Request.QueryString(); function finds the parameter by name and returns its value.
The second option, without saving the report template in the project:
Here, we create a report object, load a template into it, and assign parameters. After that, we assign the report object to the web report object. Forgive me for the tautology. At the same time, make sure that the property of the ReportResourceString WebReport is empty.
Both methods lead to the same result:
Thus, just a few lines of code allow you to use parameters passed in the URL.