logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • 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
  • Interactive web report with drill down lists

    August 15, 2017

    In this article we look at how to create interactive reports with drop-down groups. We

    read more
  • How to use FastReport Core Web Report in Angular 7

    April 29, 2019

    The concept of one-page apps is finding an increasing number of supporters. One of the

    read more
  • How to create a report from web application code

    February 16, 2022

    Sometimes creating a report can turn into to be a real headache. For example,

    read more
  • How to use FastCube .NET in the SPA application Knockout.js

    July 21, 2021

    To output the data cube, we will create a SPA application by means of Knockout.js

    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 buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.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
  • FAQ
  • Tutorial Video
  • Forum
  • Support SLA
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy

Trustpilot