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
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.
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
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.
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
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.
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
I opened your project and ran the Upgrade wizard, set it to Q1 2013, and ran the project. It did NOT work. (zero parameters)
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.
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
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.
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
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.