FlexReport for .NET | ComponentOne
In This Topic
    Report Parameters
    In This Topic

    Parameters are used to take inputs from users prior to generating the report. The users can answer the prompt prior to report generation. The output of the report depends on the response of the user for the parameter value. FlexReport adds new properties for defining Parameters. The Data tab defines different Parameter fields, such that each parameter has it's own set of properties.

    Report parameters in FlexReport can be used to perform the following tasks:

    Adding parameters to a report

    The steps to add parameter to a report are as follows:

    1. Run FlexReportDesigner.exe application.
    2. Create a new report. Bind it to a data source, which is the Main data source. The report opens in the Design mode.
    3. Click the Data tab.
    4. Right-click Data Sources and click Add Data Source to add a data source for specifying a parameter. Add as many data sources as the number of parameters that need to be added to the report.
      Add Multiple data source
    5. Right-click Parameters and select Add Parameter from the context menu.
      Add Parameters
    6. Set the properties of parameters from the Properties window depending upon the task that needs to be accomplished using parameters.

    Data Binding in Parameters

    To perform data binding in report parameters, the steps are as follows:

    1. Run FlexReportDesigner.exe application.
    2. Create a new report. Bind it to a data source, which is the Main data source. The report opens in the Design mode.
    3. Click the Data tab.
    4. Right-click Data Sources and select Add Data Source The Data Sources dialog box appears.
      Data sources
    5. Select a Data Source, say DataSource1, to create a new data source and set Connection, Data provider, Connection string, etc.
    6. You can rename DataSource1 from the Properties window by setting Name property. In our case, we have set Name to dsCategories.
    7. Add a parameter by right-clicking Parameters and then selecting Add Parameter.
    8. From the Properties window, click the ellipsis button next to AllowedValuesDefinition. The AllowedValuesDefinition Editor dialog box appears.
      Allowed values definition editor
    9. Select the From Data Source radio button and then select Data Source, Label, and Value for binding the data source to the parameter as shown. Click OK.
    10. From the Properties window, set the DataType to a value that is same as the data type of Value in the AllowedValuesDefinition Editor. In our case, DataType is set to Integer since Value=CategoryID is integer. 

    Create Expressions for Calculated Fields

    Parameters can be used to create expressions for calculated fields. To use parameters to perform various calculations in the report, perform the steps below:

    1. Run FlexReportDesigner.exe application.
    2. Create a new report. Bind it to Products table. The report opens in the Design mode.
    3. Click the Data tab.
    4. Right-click Data Sources and select Add Data Source. The Data Sources dialog box appears.
    5. Add another Data source and bind it to Products table. This data source is added for the parameter. Name this data source as 'dsProducts'.
    6. Add a parameter 'Parameter0' by right-clicking Parameters and then selecting Add Parameter
    7. From the Properties window, click the ellipsis button next to AllowedValuesDefinition. The AllowedValuesDefinition Editor dialog box appears.
    8. Select the From Data Source radio button and then select Data Source - dsProducts, Label - ProductName, and Value - ProductName. Click OK.
    9. Add another parameter 'Discount'.
    10. Edit the 'Main' data source. Write following Sql statement:
      Select * from Products where ProductName=Parameter0
    11. Add a Calculated field from the Fields group in the Insert tab. The VBScript Editor opens.
    12. Specify the following expression in the editor:
      UnitPrice*Discount
    13. Drop the Calculated field in the Detail section. Also add a Text field to display 'Discounted Price' in the PageHeader section.

      Parametrized calculated field

    14. Preview the report. Select the product name from Parameter0 and enter the discount value in Discount parameter. The discounted price is calculated on clicking Apply Parameters.     

      Preview Parametrized calculated field

    Pass Parameters to Subreports

    Subreports are useful in displaying additional information about the data present in the main report. Just as you pass parameters to a report, you can also pass parameters to subreports and create connection between the data values in subreports.

    For instance, you want to fetch data in subreports that are rendered side by side on a main report. The steps to attain such a scenario are as follows:

    1. Run FlexReportDesigner.exe application.
    2. Create a new report definition, main report, in an unbound mode.
    3. Create another report and bind it to Photos report available in the C1NWind.mdb.
    4. From the Insert tab, click Subreport field. All the available reports will be displayed.
    5. Drop two Subreport fields side by side.
    6. Add two parameters that will be passed one for each subreport.
    7. Set the name of parameters from Name property - 'prmLeftPlace' for parameter on left subreport and 'prmRightPlace' for parameter on right subreport.
    8. Add Data Source for parameters - set data provider and connection string. Write a Sql Statement that will be used to pass values to the parameters. For example, to select 'Place' from the 'Photos' report, the statement should be:
      select distinct Place from Photos order by Place
              
      
    9. Set AllowedValuesDefinition property for both the parameters - 
      1. Click the ellipsis button next to AllowedValuesDefinition.
      2. In the AllowedValuesDefinition Editor dialog box, select the From Data Source radio button.
      3. Select Data Source, Label, and Value for binding the data source to the parameter. 
    10. Set the prompt text from Prompt property for each of the parameter.
    11. Select Subreport -Photos- click Data tab
    12. Edit the data source and write the following Sql Statement:
      select distinct Place from Photos order by Place

    13. Select the main report and click the Subreport field on left. Click ellipsis next to ParameterValues.ParameterValuesCollection Editor appears. Set the Name and Value as shown.
      Parameter Values Editor
    14. Similarly, set the Name - prmPlace and Value - prmRightPlace.Value for Subreport field on the right. In the design view the report should look similar to the following:Preview report
    15. Preview the report.

      Display report after selecting the report parameter

    You can see two parameter prompts with a list of values (i.e. places), one for each subreport. Select the values and click Apply Parameters. Here, we have selected Chaumont for left subreport and Cote d'Azur for right subreport.

    Cascading Parameters

    Cascading parameters are used when a list of values in one parameter depends on the value selected for the other parameter. So you have two parameters, where one parameter alters the data source used to list data values for another parameter.

    For instance, if you want to select a Product from a list of products that belong to the selected Category, then you need to do the following:

    1. Create a new report. Bind the report to Order Details available in C1NWind.mdb.
    2. Add two Data Sources, one for each parameter:
      • dsCategory to pass values to parameter prmCategory
      • dsProduct to pass values to parameter prmProduct

        Cascading Parameters
    3. Right-click dsCategories and select Edit to edit the data source. Set Data provider, Connection string, and write following Sql Statement:

      select * from categories

    4. Repeat the previous step for dsProducts. Write the following Sql Statement:

      select * from products where categoryid = prmCategory

    5. Right-click Main data source, select Edit and write Sql Statement for Main data source:

      select * from [order details] where productid = prmProduct

    6. Add two parameters:
      • prmCategory to select Category.
      • prmProduct to select Product that belongs to the category selected in prmCategory parameter.
    7. Set the AllowedValuesDefinition property for both the parameters as shown:
      prmCategory prmProduct
      Data Source dsCategory dsProduct
      Label CategoryName ProductName
      Value CategoryID ProductID
    8. Click Preview.
      Cascading parameters preview

    On selecting a category, a list of products available in that category are displayed in the other parameter. You can then select the product and then click Apply Parameters. Here, we have displayed data in Aniseed Syrup product that falls in the Condiments category.

    Multi-value Parameters

    Multi-value parameters are parameter collections that allow you to pass multiple values for a parameter; that is, you can select multiple data from a list of data.

    In FlexReportDesigner application, a parameter can be made multi-value by setting Parameter.MultiValue to True.

      Multi Value Property

    On previewing a report with multi-value parameter, a list of values bound to the parameter is displayed. You can then select the values that you want to be rendered in the report.

    Preview multi-value parameter

    Pass Parameters Silently

    Passing the parameters silently allows passing the values of the parameters without any user prompt (or user interaction), while rendering the report.

    To pass the parameters silently, define parameter properties and set Parameter.Hidden property to True.

     Passing parameters