This is a migrated thread and some comments may be shown as answers.

Pass Report parameters from Rad window to a telerik report

1 Answer 284 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
smith spd
Top achievements
Rank 1
smith spd asked on 08 Nov 2010, 11:31 PM

Hello Telerik Team,

I have a requirement where I need to show a rad window on a telerik report.In this rad window I will have three paramaters with their own values.When the user selects a paramater and its value from the rad window do you pass these values to the report.

I have the rad window working with combo boxes and i am storing the value from the rad combo box in a view state variable.I have added the report parameters programatically.But how do i pass these values to my report which consists of many formulae computed based on these parameter values.
I greatly appreciate your help.

Please provide me a sample report which has this functionality.

Thank You,

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 09 Nov 2010, 04:09 PM
You'll have to retrieve the report parameters values from the UI, and pass them to the report constructor. In the following snippet, I'm using session variables to pass the parameters to the page that actually displays the report.

protected void Page_Load(object sender, EventArgs e)
  IReportDocument reportDocument = null;
  string reportName = Request.Params["ReportName"].ToString();
  // retrieve contents of session variables that are applicable to one or more reports
  string fyCode = Session["fyCode"].ToString();
  string fyPeriod = Session["fyPeriod"].ToString();
  string rsIndicator = Session["rsIndicator"].ToString();
  bool clearingAccounts = Convert.ToBoolean(Session["clearingAccounts"]);
  // session variable containers for specific reports
  string deptCode = string.Empty;
  string budgetCode = string.Empty;
  string budgetCodeDescription = string.Empty;
  string subDepartments = string.Empty;
  string laborType = string.Empty;
  string classGroup = string.Empty;
  string deptName = string.Empty;
  switch (reportName.ToLower())
    case "budgetcomparativemasterreport":
      deptCode = Session["deptCode"].ToString();
      this.Title = "Budget Comparative Report";
      reportDocument = new ETLReportsLibrary.BudgetComparativeMasterReport(fyCode, fyPeriod, rsIndicator, deptCode, clearingAccounts);
  if (reportDocument != null)
    this.ReportViewer1.Report = reportDocument;

Then the constructor for the BudgetComparativeMasterReport looks like this:

public BudgetComparativeMasterReport(string fy_code, string fy_period, string rollup_section_ind, string dept_code, bool clearingAccounts)
  /// <summary>
  /// Required for Telerik Reporting designer support
  /// </summary>
  // TODO: Add any constructor code after InitializeComponent call
    // populate the report parameters with the values passed as arguments
    this.ReportParameters["fy_code"].Value = fy_code;
    this.ReportParameters["fy_period"].Value = fy_period;
    this.ReportParameters["rollup_section_ind"].Value = rollup_section_ind;
    this.ReportParameters["dept_code"].Value = dept_code;
    this.ReportParameters["fiscal_period_ending"].Value = ReportUtilities.GetPeriodEndingDate(fy_code, fy_period);
    this.ReportParameters["clearing_accounts"].Value = clearingAccounts;
    // display the selected fiscal year and period in the upper l/h corner of the page header
    this.txtFyCodePeriod.Value = string.Format(this.txtFyCodePeriod.Value, fy_code, fy_period);
    // display whether or not the values include/exclude the clearing accounts in the upper l/h corner of the page header
    this.txtClearingAccounts.Value = string.Format(this.txtClearingAccounts.Value, clearingAccounts == true ? "Included" : "Excluded");
    // release the .DataSource property of this report, this will force the NeedDataSource event handler
    // to be fired when the report is rendered
    this.DataSource = null;
    // wire-up the event handler
    this.NeedDataSource += new EventHandler(budgetComparativeMasterReport_NeedDataSource);
    // set the "clearing_accounts" parameter of the 3-subreports
    this.payroll1.ReportParameters["clearing_accounts"].Value = clearingAccounts;
    this.laborSubreport1.ReportParameters["clearing_accounts"].Value = clearingAccounts;
    this.capitalSubreport1.ReportParameters["clearing_accounts"].Value = clearingAccounts;
  catch (System.Exception ex)
    // An error has occurred while filling the data set. Please check the exception for more information.

Then, the .NeedDataSource event handler, for the master report, looks like this. You can see how I'm plugging in the report parameters, assigned in the constructor, into the query that's executed:
private void budgetComparativeMasterReport_NeedDataSource(object sender, EventArgs e)
    if (this.dataSource == null)
      // collect the report parameter values assigned in the class constructor, the values
      // will be substituted in the SQL statement via the string.Format() method
      string fyCode = (sender as Telerik.Reporting.Processing.Report).Parameters["fy_code"].ToString();
      string rollupSectionInd = (sender as Telerik.Reporting.Processing.Report).Parameters["rollup_section_ind"].ToString().ToUpper();
      string deptCode = (sender as Telerik.Reporting.Processing.Report).Parameters["dept_code"].ToString();
      string connectionString = ReportUtilities.ConnectionString; 
      string sqlSelect =
            DISTINCT dept_code,
            fy_code = '{0}' AND
            Upper(rollup_section_ind) = '{1}' AND
            dept_code LIKE '{2}'";
      OracleDataAdapter da = new OracleDataAdapter(string.Format(sqlSelect, fyCode, rollupSectionInd, deptCode), connectionString);
      this.dataSource = new DataSet();
      // display the data source in the upper l/h corner of the page header
      this.txtDataSource.Value = string.Format(this.txtDataSource.Value, da.SelectCommand.Connection.DataSource.ToString().ToUpper());
    (sender as Telerik.Reporting.Processing.Report).DataSource = this.dataSource;
  catch (Exception ex)

Hope that helps...
General Discussions
Asked by
smith spd
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Share this question