Parameterized Report: Using Parameters for Filtering

Download the sample application: ReportWithParameters.zip

To use parameters from the application in a template, it is necessary:

  1. To declare the parameters in the template. 
  2. To use the parameters during the template creation. 
  3. To pass parameters from the application to the template.

Let’s examine the example of the report stating the range of books. The parameter passed from the application is used as a filter for the list.

The parameter is added to the Document.Parameters collection: Name = Filter, during the report creation in the designer.

The template looks as follows:

The GetParameter(“Filter”) function is used to get the parameter value.

The PageHeader section includes TextBox which outputs the parameter value. The TextBox.Value = GetParameter(“Filter”).

The DataBand.FilterExpression property:

GetParameter("Filter").ToString() == "" 
|| GetData("bookstore.title").ToString().ToLower()
   .Contains(GetParameter("Filter").ToString().ToLower()) 
|| GetData("bookstore.price").ToString().ToLower()
   .Contains(GetParameter("Filter").ToString().ToLower()) 
|| (GetData("bookstore.author.firstname").ToString() +
   + " " + GetData("bookstore.author.lastname")).ToString()
   .ToLower().Contains(GetParameter("Filter").ToString().ToLower()) 
|| (GetData("bookstore.author.lastname").ToString() + 
   +" " + GetData("bookstore.author.firstname")).ToString()
   .ToLower().Contains(GetParameter("Filter").ToString().ToLower())

The result of calculation of the expression of the DataBand.FilterExpression property is true, if the parameter is an empty string or any record from the data source includes string parameter.

The GetReportParameter event handler looks as follows:

private void inlineReportSlot1_GetReportParameter(object sender, 
PerpetuumSoft.Reporting.Components.GetReportParameterEventArgs e)
 {
    e.Parameters["Filter"].Value = filterTextBox.Text;
 }

The application form:

The filterButton button forms the report. The report data is filtered according to the value set in filterTextBox:

Add Feedback