ActiveReports 11
Add Parameters in a Section Report
ActiveReports 11 > ActiveReports User Guide > How To > Section Report How To > Add Parameters in a Section Report

There are several ways to add parameters in a section report. The following sections provide a step by step overview of adding parameters in a report.

To add parameters using the Report Explorer

  1. In the Report Explorer, right-click the Parameters node and select Add. This adds a parameter (Parameter1) as a child to the Parameters node.


  2. Select the added parameter to open the Properties Window and set values in the following properties:
    • Name: This is the unique name of the parameter which appears as Parameter1 by default. It corresponds to the Key property in parameters entered via code.
    • Default Value: Sets/returns the value displayed when the user is prompted to enter a value at run time.
    • Prompt: Sets/returns a string displayed when a user is prompted for the value at run time.
    • PromptUser: Boolean value that indicates whether to prompt the user for a value or not. This is set True to use parameters at run time.
    • Type: This value which defaults to String defines the type of data the parameter represents. You can also set data type to Date or Boolean.
  3. Pass the parameter to a field on the report, or access it programmatically as described in the run time procedure below.

To add parameters directly using a SQL query

When you add SQL parameters to a report, ActiveReports displays an Enter Report Parameters dialog where the user can enter the values to fetch from the database.

  1. In the detail section band, click the DataSource icon to view the Report Data Source dialog.
  2. Connect the report to a data source, for example, OleDb data source. See Bind Reports to a Data Source for further details.
  3. In the Query field, enter a SQL query like the one below, which contains the parameter syntax to prompt for parameter values at run time.
    SELECT * FROM Products
    INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID= [Order Details].OrderID)
    ON Products.ProductID = [Order Details].ProductID
    WHERE Products.SupplierID = <%SupplierID|Enter Supplier ID|7%>
    AND OrderDate >= #<%OrderDate|Order date from|11/1/1994|D%>#
    AND Discontinued = <%Discontinued|Is this checked?|true|B%>
  4. Click OK to save the data source and return to the report design surface.

    The SQL query above causes ActiveReports to display the following dialog to the user. The user can accept these or input other values to select report data.

To add parameters at run time

You can add, edit, and delete parameters at run time. The following code demonstrates how to add a parameter and display its value in a Textbox control.

  1. Double-click in the gray area below the report to create an event-handling method for the ReportStart event.
  2. Add code to the handler to set parameters at run time.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste at beginning of code view. 
    Copy Code

    Imports GrapeCity.ActiveReports.SectionReportModel

    Visual Basic.NET code. Paste INSIDE the ReportStart event.
    Copy Code

    Dim myParam1 As New Parameter()
    myParam1.Key = "myParam1"
    myParam1.Type = Parameter.DataType.String
    'Set to False if you do not want input from user.
    myParam1.PromptUser = True
    myParam1.Prompt = "Enter Data:"
    myParam1.DefaultValue = "Default Value"
    Me.Parameters.Add(myParam1)

    To write the code in C#

    C# code.  Paste at beginning of code view.
    Copy Code

    using GrapeCity.ActiveReports.SectionReportModel;

    C# code. Paste INSIDE the ReportStart event.
    Copy Code

    Parameter myParam1 = new Parameter();
    myParam1.Key = "myParam1";
    myParam1.Type = Parameter.DataType.String;
    //Set to False if you do not want input from user.
    myParam1.PromptUser = true;
    myParam1.Prompt = "Enter Data:";
    myParam1.DefaultValue = "Default Value";
    this.Parameters.Add(myParam1);

  3. In the design view, click the gray area below the report to select it and open the Properties Window.
  4. Click the events icon in the Properties Window to display available events for the report.
  5. Double-click FetchData. This creates an event-handling method for the report's FetchData event.
  6. Add code to the handler to pass the parameter at run time.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the FetchData event.
    Copy Code
    'Set textbox text equal to the value of the parameter.
    Me.txtParam1.Text = Me.Parameters("myParam1").Value

    To write the code in C#

    C# code. Paste INSIDE the FetchData event.
    Copy Code
    //Set textbox text equal to the value of the parameter.
    this.txtParam1.Text = this.Parameters["myParam1"].Value;
    The run-time implementation above causes ActiveReports to display the following dialog to the user. The user can enter any text in this prompt dialog and display it on the report.

To View a Parameterized Report

The parameter prompt dialog for a parameterized report depending on how you view the report.

To get a Parameter Dialog box

  1. In the Visual Studio project, add a Viewer control to the Form.
  2. Double-click the Form title bar to create a Form_Load event.
  3. Add the following code to the handler to view the report in the Viewer.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Form_Load event.
    Copy Code
    Dim rpt As New SectionReport1
    Viewer1.Document = rpt.Document
    rpt.Run()

    To write the code in C#

    C# code. Paste INSIDE the Form_Load event.
    Copy Code
    SectionReport1 rpt = new SectionReport1();
    viewer1.Document = rpt.Document;
    rpt.Run();

To get a Parameter Panel in the Viewer sidebar

  1. In the Visual Studio project, add a Viewer control to the Form.
  2. Double-click the Form title bar to create a Form_Load event.
  3. Add the following code to the handler to view the report in the Viewer.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Form_Load event.
    Copy Code
    Dim rpt As New SectionReport1
    Me.Viewer1.LoadDocument(rpt)

    To write the code in C#

    C# code. Paste INSIDE the Form_Load event.
    Copy Code
    SectionReport1 rpt = new SectionReport1();
    viewer1.LoadDocument(rpt);
See Also

Concepts