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

Get reports parameters and values from Report Viewer

7 Answers 851 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Avesh
Top achievements
Rank 2
Avesh asked on 20 Jan 2011, 04:52 PM
Hi

I need to save a reports parameters and their values. Passing the report to the report viewer control makes life alot easier as the control builds all the neccesary parameters.
Is there a way to get the event that the Preview button fires? i would think that this event will pass all parameters and values to the actual report for it to be rendered, and i can simply get the parameters and values from its event args.
If its not possible, is there another way that can be helpful for my scenario.  

thanks
Avesh

7 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 20 Jan 2011, 05:12 PM
Hello Avesh,

The parameter values are available in the ItemDataBound event:

private void Report1_ItemDataBound(object sender, EventArgs e)
       {
           Telerik.Reporting.Processing.Report rpt = (Telerik.Reporting.Processing.Report)sender;
           var obj = rpt.Parameters;
       }

Another approach is implementing your own UI for handling the parameters and wire it to the Report API for passing the values.

Regards,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Avesh
Top achievements
Rank 2
answered on 21 Jan 2011, 10:36 AM
Hi Steve

Thanks for that, i am able to get the parameters from the itemdatabound event.
Is there a way to not display the report after clicking preview. The main thing that i want are the parameter collection and values.
This will be opened in a popup and it will return the parameter collection to the parent page.

Is the a sample available on a custom UI for handling the parameters?

Many thanks
Avesh
0
Steve
Telerik team
answered on 26 Jan 2011, 05:12 PM
Hello Avesh,

This is how the ASP.NET viewer works in the current implementation when all report parameters have value and this behavior cannot be changed. If the user is to select a parameter prior running the report, do not set default values for the parameters.
If you want to avoid running the report, what you can do is implement your own UI for the report parameters that is wired to the Report API and this way the report would not be run until you press a "Preview/Run Report" button from your UI e.g.:

Telerik.Reporting.Report report = (Telerik.Reporting.Report)this.ReportViewer1.Report;
report.ReportParameters["MyParam"].Value = TextBox1.Text;


Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Trung
Top achievements
Rank 1
answered on 02 May 2011, 10:44 AM
Hi Steve,

If I use Silverlight Reporting Viewer, how can I code as you mentioned ?
as
Telerik.Reporting.Report report = (Telerik.Reporting.Report)this.ReportViewer1.Report;
report.ReportParameters["MyParam"].Value = TextBox1.Text;

in silverlight, I can see the type of this.ReportViewer1.Report is string.

if possible, please provide us an example of how to do transfer the report parameters selected in GUI then to the report within the report viewer control in Silverlight.

Thanks,
Trung
0
Steve
Telerik team
answered on 02 May 2011, 04:55 PM
Hi Trung,

The following KB article elaborates on setting values to report parameters from Silverlight application: Programmatic Initialization of Report Parameter Values in Telerik Reporting Silverlight Viewer.

All the best,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Frank
Top achievements
Rank 1
answered on 14 Oct 2011, 03:05 PM
Hi Steve, 
I was able to set the parameters of my report with the RenderBegin event when I open or Preview it. The only thing missing for me is to be able to get the parameters when the user hits the Preview button, so we can save them for later. I know I can save them on the ItemDataBinging event of the report, but I was wondering if it could be done from the report viewer instead of the report itself. 

If not, isn't it a little confusing? Let's say I want to populate the report parameters stored in an external file, and save the parameter values in this file when the user hits Preview. If I populate the report on the RenderBegin event at first, then the user changes some values and hits Preview, the RenderBegin event is called again and loads the stored parameter values (overriding the changed values), THEN the ItemDataBinding event is called and saves... the original parameters from the file! 

So is there a way to get around this problem? 

When raised the first time, the RenderBeginEventArgs contains no parameters so I can populate them. Then when Preview button is hit, the args contains the changed parameter values. Maybe I can use this to keep the report from re-loading the parameters again. Is this the best way to do it? 

Also, subscribing to the ItemDataBinding event would save the parameters every time the user clicks the Preview button. If there is a way to handle it from outside the report, we could save them only when we want. 

Thank you
0
Squall
Top achievements
Rank 1
answered on 19 Oct 2011, 03:06 PM
Hi,
You can try to implement some custom logic and compare the old report parameter values you have saved in some custom storage against the new ones.  Then save the report parameter values only when they are different from the values in your storage. This seems will be easier if implemented in itemdatabinding.
SN
Tags
General Discussions
Asked by
Avesh
Top achievements
Rank 2
Answers by
Steve
Telerik team
Avesh
Top achievements
Rank 2
Trung
Top achievements
Rank 1
Frank
Top achievements
Rank 1
Squall
Top achievements
Rank 1
Share this question
or