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

Setting report parameters via webiste code behind?

2 Answers 413 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark Jones
Top achievements
Rank 1
Mark Jones asked on 23 Jun 2009, 12:59 AM
Hi, can some-one please help me with the following issue re passing parameters.

I have created a new trivial report and setup two report parameters

1) StartDate (Type DateTime)
2) EndDate (Type DateTime)

What I would like to be able to do is set the report parameters from inside the codebehind of the webpage which will display the report.

e.g.

The report object is in a seperate class library called ProductOrders

 public partial class ProductOrders : Telerik.Reporting.Report
    {
            
        public ProductOrders()
        {                   
             try
            {
                this.dsAllOrdersTableAdapter1.Fill(this.dsAllOrders.dsAllOrdersTable);
            }
            catch (System.Exception ex)
            {
                // An error has occurred while filling the data set. Please check the exception for more information.
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }

}       


In another .NET website project I have a report viewer called ReportViewer1 and I have the following code

protected void Page_Load(object sender, EventArgs e)
{                
    // New instance of the ProductOrders report
       ProductOrders _report = new ProductOrders();

    
    // Set the report parameters here
       _report.ReportParameters["StartDate"].Value = Convert.ToDateTime("01-jun-2009");
       _report.ReportParameters["EndDate"].Value = Convert.ToDateTime("30-jun-2009");
                   
    // associate the report with report viewer
       ReportViewer1.Report = _report;
}

The problem that I am having is that the report paramaters are *always null* when I set them from the website page.
If I place them inside the constructor of the ProductOrders they work fine.
I do not want to pass through this information in the QueryString but would prefer to pass them through programatically. Again the above is a trivial example :)

Thanks in advance
Mark

2 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 23 Jun 2009, 06:20 AM
Hello Mark,

Actually your code is correct and testing this on my end - it works correctly. So there must be something else that is causing the problem. Please provide more info on your scenario or a link to a sample project that exhibits the problematic behavior.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Peter
Top achievements
Rank 1
answered on 24 Jul 2014, 02:08 AM
This worked for me,  creating the parameter and doing  a .Parameters.Add(parameter);           

            var typeReportSource = new Telerik.Reporting.TypeReportSource();
            typeReportSource.TypeName = "Acme.Sales.APJ.ReportLib.Survey, ReportingLib";

            var param1 = new Telerik.Reporting.Parameter("SurveyID", Request["id"].ToString());
            typeReportSource.Parameters.Add(param1);

            var param2 = new Telerik.Reporting.Parameter("Name", Request["n"].ToString());
            typeReportSource.Parameters.Add(param2);

            this.ReportViewer1.ReportSource = typeReportSource;  
Tags
General Discussions
Asked by
Mark Jones
Top achievements
Rank 1
Answers by
Steve
Telerik team
Peter
Top achievements
Rank 1
Share this question
or