logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • ru
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to pass parameter into report through URL
  • How to use WebReport with ASP .Net Web Core application

    January 17, 2018

    Recently FastReport introduced a new library under the .Net - FastReport Core platform. This is

    read more
  • Report generators family FastReport brief review

    March 23, 2020

    Without reporting it is impossible to carry on business in any sphere of life. Bureaucracy

    read more
  • How to use Online Designer in ASP .Net Core

    January 17, 2018

    One of the novelties by FastReport .Net 2018 was the adaptation of OnlineDesigner to the

    read more
  • How to create a custom toolbar for web FastReport.NET report

    May 31, 2020

    Many users of report generators are interested in setting up the toolbar when reviewing the

    read more
  • How to update the FastReport.Core web report

    September 21, 2020

    Sometimes you need to update the report, for example if you input a new variable

    read more

How to pass parameter into report through URL

August 23, 2017

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: 

1
2
using FastReport.Web;
using FastReport;

 I used the Load page event, because at this stage the report is not yet displayed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
namespace URLParams
{
 public partial class About : Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {
//Get parameters from URL
 string param1 = Request.QueryString["param1"];
 string param2 = Request.QueryString["param2"];
//Load report fil into WebReport object 
 
 WebReport1.ReportFile = "App_Data/URLParams.frx";
//Set value to report parameters
 WebReport1.Report.SetParameterValue("Param1", param1);
 WebReport1.Report.SetParameterValue("Param2", param2);
 }
 }
}

 Note that the parameter name exactly matches the parameter name in the report template:

1
WebReport1.Report.SetParameterValue("Param1", param1);

 The URL looks like this:

http://localhost:51838/About?param1=Hello%20World!&param2=Good%20job!

The Request.QueryString(); function finds the parameter by name and returns its value.

The second option, without saving the report template in the project:       

1
2
3
4
5
6
7
8
9
10
 protected void Page_Load(object sender, EventArgs e)
 {
 string param1 = Request.QueryString["param1"];
 string param2 = Request.QueryString["param2"];
 Report report = new Report();
 report.Load("J:/Program Files (x86)/FastReports/FastReport.Net/Demos/Reports/URLParams.frx");
 report.SetParameterValue("Param1", param1);
 report.SetParameterValue("Param2", param2);
 WebReport1.Report = report;
}

 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.

about product download buy
avatar
Dmitriy Fedyashov
Head of QA
.NET FastReport ASP.NET WebReport

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Our team
  • Contact us

© 1998-2021 by Fast Reports Inc.

  • Privacy Policy