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

Accessing Report Params

12 Answers 542 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 27 Sep 2013, 03:58 PM
Recently we upgraded our version of Telerik Reporting.  In a few of our reports, the way we were accessing the report param selected values in the code behind broke, but we made the necessary corrections to access the parameter values.

However, we still have a scenario where I can't seem to access the values of the report parameters...

We have a aspx page that contains a telerik ReportViewer.  Also on the page, we have a save button - that allows them to save the parameters they have selected in the report that is displayed in the ReportViewer.   So in the code we get the ReportSource of the ReportViewer, and then pull the values of the parameters, and save them to the database.  When we upgraded (to Q1 2013), this stopped working. (the values for the parameters are always null (or the default))

We were accessing the parameter like this:
Telerik.Reporting.IReportDocument document =
   ((Telerik.Reporting.InstanceReportSource)this.ReportViewer1.ReportSource).ReportDocument;
 
foreach (Telerik.Reporting.ReportParameter p in document.ReportParameters)
{
  object value = p.Value;
}   

 

Is there a way of getting the parameter values?


12 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 02 Oct 2013, 12:17 PM
Hello Justin,

Currently the ReportSources are holding the parameter values. Simply use the ReportSource's parameters collection to get the values:
((Telerik.Reporting.InstanceReportSource)this.ReportViewer1.ReportSource).Parameters
 

Regards,
Elian
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Justin Lee
Top achievements
Rank 1
answered on 04 Oct 2013, 01:35 PM
There are no items in the Parameters property. I tested with a report with 4 parameters -- set the first parameter to a value, ran the report, then clicked on my 'Save' button.

In the save button event handler:
((InstanceReportSource)
this.ReportViewer1.ReportSource).Parameters
-- Contained 0 items.

((InstanceReportSource)this.ReportViewer1.ReportSource).ReportDocument.ReportParameters
-- Contained 4 items, however the value for each was null (or empty string).

((InstanceReportSource)this.ReportViewer1.ReportSource).ReportDocument.Reports.First().ReportParameters
-- Contained 4 items, however the value for each was null (or empty string).

Thanks,
Justin

0
Stef
Telerik team
answered on 09 Oct 2013, 11:44 AM
Hello Justin,

If the parameters area is visible, the selected parameters values are stored in the ReportViewer.ReportSource.Parameters collection. Take a look at the attached sample project illustrating the suggestion. Notice once the report parameters values are entered the user should hit the Preview button in order to update the ReportSource.

If you need report parameters' values in report's events, please take a look at the example in the Using Report Events help article.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Justin Lee
Top achievements
Rank 1
answered on 09 Oct 2013, 01:51 PM
So it looks like a version thing.  You built your project with 7.1.13.802.  We are currently using 7.0.13.220.  When I open your project and switch the assembly references, it does NOT work.  ReportViewer1.ReportSource.Parameters is empty.

Is there any solution for this using Q1 2013? (7.0.13.220)
We are not at a good position to upgrade right now. We have a lot of complex reports, and last time we upgraded it took a couple weeks to get the reports working correctly.


Thanks,
Justin 
0
Stef
Telerik team
answered on 14 Oct 2013, 12:40 PM
Hello Justin,

The behavior is the same with Telerik Reporting Q1 2013 SP1(edited). You can run the Upgrade Wizard to downgrade the provided example.

Basically the project contains a report with several parameters set to be Visible. Then in the page hosting the ReportViewer control we have added the following code:
protected void Page_Load(object sender, EventArgs e)
     {
         if (!IsPostBack)
             ReportViewer1.ReportSource = new InstanceReportSource { ReportDocument = new Report1() };
     }
 
     protected void Button1_Click(object sender, EventArgs e)
     {
         string text = "";
         foreach (var param in ReportViewer1.ReportSource.Parameters)
             text += param.Name + ": " + param.Value.ToString() + Environment.NewLine;
 
         Literal1.Text = text;
     }

Once the ReportViewer control's content is loaded and the user inputs values for the report parameters (hitting Preview), the ReportViewer.ReportSource is update and the parameters' values are available through the ReportViewer1.ReportSource.Parameters collection.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Justin Lee
Top achievements
Rank 1
answered on 14 Oct 2013, 02:00 PM
Are you sure?  Did you run your project using 7.0.13.220?  Like I said, I have run your sample project using 7.0.13.220 -- and the project does not work. I do click on Preview before I click "Get Parameters", and nothing happens. I put a breakpoint in the event handler, and there are ZERO parameters in ReportViewer1.ReportSource.Parameters.

I did not use the upgrade wizard to downgrade the example, I did it manually. Since I switched to VS 2012, the upgrade wizard does not popup when I open a solution, and Telerik Reporting menu does not show up (I have even uninstalled/installed telerik reporting, and installed VS 2012 support),  but that is a separate issue...  If you verify that you have tested the project after downgrading to 7.0.13.220, and it works, I will work on getting the telerik reporting menu working, so I can run the Upgrade Wizard.

Thanks,
Justin

 

0
Justin Lee
Top achievements
Rank 1
answered on 14 Oct 2013, 02:08 PM
Update -- I found the vsix file, ran it, and now have the Telerik Reporting menu.

I opened your project and ran the Upgrade wizard, set it to Q1 2013, and ran the project.  It did NOT work. (zero parameters)
0
Stef
Telerik team
answered on 14 Oct 2013, 03:18 PM
Hello Justin,

Apologies for the inconvenience.

The test was performed with Telerik Reporting Q1 2013 SP1(7.0.13.426), where we have made changes on the ReportViewer.ReportSource so it reflects the changes in the report source object used to pass the report document to the ReportViewer.

Please download and test it at your side.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Justin Lee
Top achievements
Rank 1
answered on 14 Oct 2013, 05:37 PM
If you refer to my 3rd post -- I'm asking if there is any solution to this using 7.0.13.220?  Given our number of complex reports, upgrading isn't as simple as updating our Telerik version.  When we get a new version, we usually have to spend a while fixing the reports that break from the upgrade, and then have a full regression test done.   So we typically update once a year.  Our testers missed that this feature was broke after our last update because it appeared it was working (but it wasn't), and they didn't have a test case that checked the saved reports were displaying correctly.  (they do now!)

If there is not a way to get report parameters from a ReportViewer in 7.0.13.220, we will just disable the feature, and do a Telerik update in our next major release. It sounds like that is the case.

Thanks,
Justin

0
Stef
Telerik team
answered on 18 Oct 2013, 07:11 AM
Hello Justin,

The feature will work with newer versions. If it is an option for you to save users preferences through the report, you can use the report events to get the running values of the parameters (the actually set by the user).

We apology for the caused inconvenience. Feel free to open a support ticket and send us a sample project illustrating the scenario, so we can check for a resolution with desired Telerik Reporting Q1 2013 version 7.0.13.220.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Francois
Top achievements
Rank 1
answered on 19 Feb 2014, 05:42 AM
Hi guys

I have the same issue here on v7.2.14.127.
I've designed a report with the stand alone report designer containing 1 report parameter. I copied the file's xml to my database and in my code I instantiate a new reportsource object:

Telerik.Reporting.XmlReportSource xmlReportSource = new Telerik.Reporting.XmlReportSource();
xmlReportSource.Xml = sXMLTemplate;
reportViewer.ReportSource = xmlReportSource;

However, when I try to access the ReportSource.Parameters I always get 0 count.
The template is saved with the following report parameter definition:

<ReportParameters>
    <ReportParameter Name="OrderNo" Text="OrderNo" Visible="True" />
  </ReportParameters>
<ReportParameters>
  <ReportParameter Name="OrderNo" Text="OrderNo" Visible="True" />
</ReportParameters>

Is there anything I'm missing?

Thanks
Francois
0
Nasko
Telerik team
answered on 20 Feb 2014, 05:12 PM
Hello Francois,

To access the report parameters collection of a .trdx report programmatically, you need to deserialize the report XML definition to a report object first. Then you will be able to access the Report.Parameters collection.

However, it is not required to access the Report.Parameters collection in order to just pass values to the parameters of the report from the application. You can do that via the report source you set to the report viewer:
xmlReportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNo", "SO43659"));


Regards,
Nasko
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

Tags
General Discussions
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Elian
Telerik team
Justin Lee
Top achievements
Rank 1
Stef
Telerik team
Francois
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or