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

Setting ReportParameter member values in code

3 Answers 276 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 10 Jul 2009, 07:39 PM
I am not finding any examples in the documentation on this.

I have two report parameters, and I want to populate their values in the code-behind.  The first one to be populated with a static (string) list.  The second one to be populated from a SQL datasource.

Can you point me towards some sample code for this?
Thanks

Dan

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 13 Jul 2009, 12:15 PM
Hi Dan,

It does not matter how the report parameters are populated. You can use the following code to access the report parameters from your calling application:

Telerik.Reporting.Report report = new MyReport();
report.ReportParameters["MyParam"].Value = <value>;

If in the context of the report itself - this.ReportParameters["MyParam"].Value = <value>; However keep in mind that report parameters' values are not yet available in report constructor and if your databind logic depends on them, you should use NeedDataSource event - similar implementation is shown here.

Best wishes,
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
Dan
Top achievements
Rank 2
answered on 13 Jul 2009, 02:36 PM
Sorry.  I must not have explained myself correctly.

What I am asking is how to populate the report parameters collection (their pulldown menu choices) from the code of the report.  As opposed to populating the collections using a wizard-built, design-time data source.  I need to construct the collections at runtime in the code.

So, is there a NeedDataSource event that I can use to populate the report parameter choices?  And, if so, how do I envoke it?

Thanks.
Dan
0
Accepted
Hrisi
Telerik team
answered on 16 Jul 2009, 12:45 PM
Hello Dan,

You can use the built-in functionality for cascading parameters. As example take a look at the ProductLineSales report included in the example solution. ProductSubcategory parameter depends from ProductCategory. The relation is defined in a filter expression "=Fields.ProductCategory = =Parameters.ProductCategory".

The NeedDataSource event is not raised for parameters because it cannot be used for cascading parameters (no way to define parameters dependencies). Nevertheless we would re-consider our implementation and extend the possibilities for data binding of report parameters in near feature.

Of course you can use your own custom parameter area to populate the parameters and set selected values to the report parameters before the report is rendered. Your parameter area should contain button "Refresh Report" similar to our built-in parameter are.

Sincerely yours,
Hrisi
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.
Tags
General Discussions
Asked by
Dan
Top achievements
Rank 2
Answers by
Steve
Telerik team
Dan
Top achievements
Rank 2
Hrisi
Telerik team
Share this question
or