How to pass parameter to ReportViewer

21 posts, 0 answers
  1. Filander
    Filander avatar
    5 posts
    Member since:
    Oct 2011

    Posted 13 Feb 2013 Link to this post

    Hi again, I need to pass a parameter to reportViewer, in the report that I designed in telerik report designer I added a parameter so I want to pass the values ​​from a String value outside the ReportViewer I do not want to enter the value in the field shown in the reportviewer beside the preview button. (see report.png image) and i need s

    Is there any way to access these properties? and how to resize the text box that receives the parameter because I want my reportviewer size you see in the picture but the box paraecer shrinks when I change the size of reportviewer, and I need to call the click event Preview button but from another button, is that possible? being so hide the parameter, and how I do to remove this error "An error has occurred while processing, incorrect syntax near ')' " this happens because I don't give a value I just set the "=Parameters.Name.Value"

    Sorry for my English, I hope you can help me!
  2. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 18 Feb 2013 Link to this post

    Hello Filander,

    The WPF ReportViewer control toolbar template can be edited with Blend, so you can change its controls visibility, styling and purpose. If you need to provide parameters outside of the report, you can set them to the report source instance used to map the trdx file to the ReportViewer or to the ReportViewer.ReportsSource.Parameters collection. The parameters area will be hidden if there are no visible parameters, and if you need to create custom preview button you can use the ReportViewer RefreshReport method. It is not very clear from your screenshot, however if you need to have a list of options for the report parameter in the trdx report, and it is needed to set that values outside the trdx, you will need to deserialize the trdx, then get the parameter from the definition by name and set its AvailableValues.DataSource, e.g.:
    System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
    settings.IgnoreWhitespace = true;
     
    using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("../../Report1.trdx", settings))
    {
        Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
            new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
     
        Telerik.Reporting.Report report = (Telerik.Reporting.Report)
            xmlSerializer.Deserialize(xmlReader);
     
        report.ReportParameters["Parameter1"].AvailableValues.DataSource = GetParamData();
     
        report.DataSource = GetData();
     
        var instance = new InstanceReportSource() { ReportDocument = report };
        instance.Parameters.Add("Parameter1", "some value");
        reportViewer1.ReportSource = instance;
    }
    reportViewer1.RefreshReport();

    About the shrinking report parameters area, it re-sizes according to the window if no explicit Width and Height are set.

    If you have further questions, please send us more details about how you provide the parameters to the report, are there any expressions used, how you use the trdx definition to display the report in a WPF ReportViewer, what is the scenario and the idea of the UI customizations you ask for.

    All the best,
    Stef
    the Telerik team

    HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

  3. Saul
    Saul avatar
    8 posts
    Member since:
    Jan 2014

    Posted 29 Jan 2014 Link to this post

    How can i pass the hidden parameters to Telerik Reports?

    I develop MVC and Telerik Report  with "Telerik report Tool" and it gives me a .trdx file so I integrated that report to my project with Uri; But now i want to pass some hidden parameters to this report 

    How can i do this?
  4. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 03 Feb 2014 Link to this post

    Hi Saul,

    The report parameters should be declared in the report definition as explained in the How to: Add Report Parameters help article. Leaving the parameters Visible properties to False, will hide them(the viewer's parameter area will not be shown). Then using the report source object, you can pass values to the parameters from outside the viewer.

    In MVC projects utilizing the new HTML5 Report Viewer, you can use the approach illustrated in the How To: Pass values to report parameters help article.

    I hope this information helps you.

    Regards,
    Stef
    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.

  5. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 03 Dec 2014 in reply to Stef Link to this post

    Hello together

    What I don't understand.
    I guess I've now set up the HTML5-Viewer correctly.

    The Sample has a visible report parameter "Date". So therefore a calendar appear where I can choose a date,
    But nothing changes when I change the date. It is always passed "new Date()".
    This make not much sense. How can I achieve that the Telerik filter controls choice get passed to the report as in the demos?

    Thank you!
  6. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 05 Dec 2014 Link to this post

    Hi Fridli,

    Please use Fiddler to record the request sent on selecting a new parameter's value and pressing the Preview button - HTML5 Report Viewer. Download and install Fiddler, then run it in parallel to the application running in browser. In Fiddler - Inspectors - Request - Raw will be displayed the URL and the content of the selected request.

    Verify the project fulfills the minimum system requirements for the HTML5 Report Viewer and Reporting REST service. Note that Newtosoft.Json.dll must not be installed in the GAC, but rather has to be updated from Nuget to the latest available version. It i used on sending report parameters' values, where parameters names are case sensitive.

    Let us know if you need further help.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 05 Dec 2014 in reply to Stef Link to this post

    Hello

    Thanks for your response!

    So you mean the following is not wrong and only an initial parameter value and the filter controls should pass their values automatically beside of this?

     // Parameters name value dictionary
    parameters: {
                 Date: new Date(),
    }

    I guess the requirements should be fine. I've set up VS 2013 and used your HTML5-Viewer template for creating a new project.
    First, everything seemed fine except the filtering problem and that I wasn't able to expand the content in the sample report.
    So I added some handlers and binding redirects in the web.config and then expanding the sample report's content worked too.
    No other changes except making the Date parameter auto refreshing. But this didn't change the behaviour in general.
    So for the following I din't have to click the preview button but I guess this doesn't make really a difference.
    But why the parameter is "undefined" instead of "Date" is weired and looks more like client-side problem...?

    {"report":"SampleReport.trdx","parameterValues":{"undefined":"2014-12-17T15:22:50.523Z"}}
    {"format":"HTML5Interactive","deviceInfo":{"ContentOnly":true,"BasePath":"api/reports"}}

    Regards
  8. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 09 Dec 2014 Link to this post

    Hello Fridli,

    If by any chance you have not checked the used Newtosoft.Json.dll, please verify it is not installed in the machine's GAC, and the project's reference is updated through Nuget to the latest available version.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 11 Dec 2014 Link to this post

    Hello Fridli,

    After another community member reported the same problem and sent us an example, it appears the HTML5 Viewer template scenario does not install the required the required Microsoft ASP.NET Web API Web Host package. The full settings are listed in How To: Add Telerik Reporting REST Web API to Web Application.

    ​In addition, you need to update Newtosoft.Json.dll from Nuget to overcome the problem with report parameters.

    Your Telerik points are updated as you are the first to report the problem.


    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 15 Dec 2014 in reply to Stef Link to this post

    Hello Stef

    Thank you very much for the information provided!
    I missed checking the Newtonsoft.Json.dll. It's v4.5.11.15520 from Aug. 2013.
    I see the current version is v6 from Oct 24, 2014. I'll try the update and see how it's doing then.

    I'll also again have a look at the Web API but I guess I already tried updating/installing it some time ago when the viewer didn't even properly reload content but this I was able to fix with the binding redirects.

    I'll come back to you when the problem is fixed with your suggestions or not...

    Best regards


  11. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 15 Dec 2014 in reply to Stef Link to this post

    Hello Stef

    Sorry I told you something wrong.
    The Newtonsoft.Json.dll is from another project where the report viewer should go some time (both in the bin folder).
    In the test project it was some 4.5 or so from 2014.
    I also saw that referenced in the project is System.Net.Http.WebRequest and System.Net.Http v4.0.30319 (with Binding redirects in web.config) but in the bin folder was 4.0.20710.
    I removed these but they are back again in the bin folder.

    Anyway, I updated to the current versions through NuGet:Microsoft.AspNet.WebApi.Client v5.2.2, Microsoft.Net.Http v2.2.28, Newtonsoft.Json v6.0.6.

    Now when I launch the test project I get "An exception of type 'System.MethodAccessException' occurred in mscorlib.dll" in Application_Start() when calling "ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration)".

    "Additional information: Error trying to access method "System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)", auf Methode "System.Web.Http.HttpConfiguration.DefaultFormatters()"."


    By the way. I already did the REST service How-To before I posted my first post because the issues of the template you mentioned in your last post and because it didn't work right without that.

    Best regards
  12. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 17 Dec 2014 Link to this post

    Hi Fridli,

    A part of the bug is that we have mistakenly provided a link to wrong Nuget package in the documentation article. The correct link is Microsoft ASP.NET Web API Web Host 4.0.30506 (WebHost package, not the Client libraries one).
    The article is updated now and points to the correct link - How To: Add Telerik Reporting REST Web API to Web Application.


    In your project:
    1. Install the Microsoft ASP.NET Web API Web Host package through Nuget (version 4.0.30506 or above);
    2. Check the Updates in the Nuget Packages manager and Update all listed packages;
    3. Check if binding redirects are applied. Visual Studio 2013 will warn you for such misconfiguration and let you add the bindings.

    The above steps will resolve the lastly reported problem, and the issue with passing report parameters.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  13. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 19 Dec 2014 in reply to Stef Link to this post

    Hello Stef

    Thanks for your help! It seems to be working fine now...
    Hoping I'll get it working too on the dev. server with IIS7 and Windows Server 2007 (?).

    Maybe you know how to install the required packages in the GAC without NuGet? Or should I just put the DLL files in the app's Bin folder?

    And maybe you too know what's the (dis)advantage of having or not having referenced to the assemblies in the web.config file.
    I noticed recently, that somebody has removed many of the assembly definitions use in the application from the web.config file.
    (<assemblies>
            <add assembly=".....)

    Best Regards

  14. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 19 Dec 2014 in reply to Fridli Jacober Link to this post

    P.S. I think the HTML5-Report viewer template is wrong too...??
    -> Installed NuGet package: Microsoft.AspNet.WebApi.Client 4.0.30506
  15. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 19 Dec 2014 Link to this post

    Hi Fridli,

    Yes, this is the original bug logged in our system. A fix will be provided in a consecutive release, where the template will install the WebHost package along with the rest of the required libraries.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  16. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 19 Dec 2014 in reply to Stef Link to this post

    Hello Steff

    Did you see the previous post too?

    p.s. is it normal, that the (multi) select filter controls do not refresh the whole report even though auto refresh is set to true?
    I tried the "Product Line Sales.trdx":
                            report: "Examples/Product Line Sales.trdx",

                            // Parameters name value dictionary
                            parameters: {
                                //Date: new Date(),
                                ProductCategory: "Bikes",
                                ProductSubcategory: "=First(Fields.ProductSubcategory)",
                                FromDate: "#2001-01-01#",
                                ToDate: "#2004-12-31#",
                            }/*,

    I don't get any JavaScript errors and the multi select doesn't even make any requests.

    thx
  17. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 19 Dec 2014 in reply to Stef Link to this post

    Hello Steff

    Did you see the previous post too?

    p.s. is it normal, that the (multi) select filter controls do not refresh the whole report even though auto refresh is set to true?
    I tried the "Product Line Sales.trdx":
                            report: "Examples/Product Line Sales.trdx",

                            // Parameters name value dictionary
                            parameters: {
                                //Date: new Date(),
                                ProductCategory: "Bikes",
                                ProductSubcategory: "=First(Fields.ProductSubcategory)",
                                FromDate: "#2001-01-01#",
                                ToDate: "#2004-12-31#",
                            }/*,

    I don't get any JavaScript errors and the multi select doesn't even make any requests.

    thx
  18. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 22 Dec 2014 Link to this post

    Hi Fridli,

    On your questions:
    1. The way you pass values to report parameters will not work and the ProductSubcategory parameter will still expect a valid value. Expressions can be set as report parameter's values only in the report's template through the report's ReportParameters collection.
      When you pass values from the viewer, they are mapped to the report source object generated by the resolver, used in the service's CreateReportResolver method.
    2. About installing packages in the GAC, it is not recommended. Instead manage them through Nuget Manager in Visual Studio. DLLs not provided by the installed frameworks, it is enough to set their CopyLocal to true and get the copies from the project's Bin folder.

    On a side note, about the <assemblies> section in your config, please check this explanation in a stackoverflow discussion.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  19. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 23 Dec 2014 in reply to Stef Link to this post

    Hello Stef

    Thanks again for the response to my questions!

    1. I wouldn't have been surprised if it didn'twork like that. But in fact it does!
    To verify it I changed First(...) to Last(...) and it works as expected (have a look at the screenshot). Or what did you mean will not work?

    But about the (Multi-Select) filter control: is it normal that it doesn't refresh the whole report even though auto refresh is set to true?
    Respectively all filters do the refresh when I set for all parameters AutoRefresh=True. But for example when only one (date) parameter has AutoRefresh=false then no filter does a report refresh, only the category filter does refresh the subcategory filter list.
    is this intended to work like that?

    2. Thanks for the information. I was just wonderin if there is any (dis)advantage having the dlls in the GAC or the Bin folder.

    P.S. I don't really understand the stackoverflow discussion. One says you cannnot remove it if you're using it (but you can).
    One talks about another secion (the controls section) which is good for not needing<%@ Register Assembly ... in every aspx page anymore for what the assemblies section isn't worth anything.

    What  I found is this interesting article where he says that you only need the assemblies section for referencing assemblies in the GAC: http://weblog.west-wind.com/posts/2009/May/04/Adding-Default-Assemblies-Namespaces-and-Control-Prefixes-in-WebConfig

    "Behind the scenes the ASP.NET compiler injects the namespace references into all generated pages and the assemblies as references to any of the dynamic assemblies it creates. By default ASP.NET includes all assemblies in the bin path, plus any GAC based assembly references in the <compilation> section of web.config. Note that you don’t need to add any private assemblies in this section – it’s only needed to add GAC references. All private assemblies in BIN folder are automatically referenced."

    Regards
  20. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 25 Dec 2014 Link to this post

    Hello Fridli,

    I believe the following blog post points the pros and cons of installing assemblies in the GAC - Working with Assemblies in the GAC. Having into account the speed of updates of Nuget packages (assemblies required for running WebAPI controllers, Netonsoft.Json.dll and etc.) it would be better if assemblies are not installed in the GAC, It will ease the deployment process as well.
    You need Telerik Reporting assemblies in the GAC of the development machine where reports will be created just to be able to work with the VS Report Designer. The assemblies can be manually copied in production.

    On the first question, you are right expressions sent from the client (viewer's reportSource.parameters) are evaluated on processing the report.
    If even one visible parameter has AutoRefresh set to false, you will have to click the Preview button to refresh the report in the viewer. Still cascading parameters will be updated on changing the major parameter's value.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  21. Fridli Jacober
    Fridli Jacober avatar
    89 posts
    Member since:
    Dec 2009

    Posted 09 Jan 2015 in reply to Stef Link to this post

    Thanks!
Back to Top