Progress® Telerik® Reporting R2 2017

Using Report Parameters programmatically

In the report viewing application you can populate the values of ReportParameters collection members prior to displaying the report.

Report1 report = new Report1();
report.ReportParameters["ManagerID"].Value = "123";

At runtime you can access the report parameters through the ReportParameters dictionary. Each Parameter object contains resolved available values, current value and label. The label returns the currently selected DisplayMember from the available values (if available values are defined).

Note Note

Prior to version 2010 Q1 the processing report exposes a dictionary containing only the current values of the report parameters.

Example:

  1. Create a Telerik Report
  2. Use the instructions from the How to: Connect to a SQL Server Database Using Stored Procedure article to bind to the uspGetManagerEmployees stored procedure from the AdventureWorks table.
  3. Leave the Value for the @ManagerID data source parameter empty and finish the wizard.
  4. Create the following layout for the report

  5. Add a report parameter and name it ManagerID.
  6. Change its Type to Integer.
  7. Set its Visible property to True.
  8. Expand the AvailableValues and bind it to SqlDataSource component with the following query:
    SELECT        M.ManagerID, C.FirstName + ' ' + C.LastName AS Name
    FROM          (SELECT DISTINCT ManagerID
                   FROM      HumanResources.Employee) AS M INNER JOIN
                             HumanResources.Employee AS E ON M.ManagerID = E.EmployeeID INNER JOIN
                             Person.Contact AS C ON E.ContactID = C.ContactID
  9. Set the ValueMember to = Fields.ManagerID.
  10. Set the DisplayMember to = Fields.Name.
  11. Add grouping for the report with = Fields.ManagerID as grouping expression.
  12. Wire the NeedDataSource event of the report.
  13. In the report.cs file set the DataSource property to null (Nothing in VB.NET) so that NeedDataSource event is fired.
  14. Add the following code to the NeedDataSource event handler:
    private void Report1_NeedDataSource(object sender, System.EventArgs e)
    {
        //Take the Telerik.Reporting.Processing.Report instance
        Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
    
        // Transfer the value of the processing instance of ReportParameter
        // to the parameter value of the sqlDataSource component
        this.sqlDataSource1.Parameters[0].Value = report.Parameters["ManagerID"].Value;
    
        // Set the SqlDataSource component as it's DataSource
        report.DataSource = this.sqlDataSource1;
    }
  15. Display the Report in a report viewer.
  16. Select a parameter from the available values in the parameter editor and click Preview.