Programmatic Initialization of Report Parameter Values in Telerik Reporting Silverlight Viewer

Monday, December 07, 2009 by Reporting Team | Comments 11
Usually one may control the report appearance and the data it displays through report parameters. The Silverlight report viewer, just like the other two, offers built-in user interface that enables end users to interact with the reports. Still there are cases when one may further need to control the report definition according to a custom logic that runs in the client application. However, since we have introduced the Silverlight Report Viewer the greatest challenge our clients have faced is that there is no direct access to the report definition in the Silverlight application.

 

To provide the ability to specify the parameter values we have decided to add a new event to the ReportViewer control called RenderBegin. As its name suggests it is raised just before the actual request for rendering is sent and has two arguments: sender which is an instance of the ReportViewer control and an instance of the RenderBeginEventArgs class. The parameter values can now be set through the ParameterValues property of the event argument. It is a name (string) – value (object) dictionary in which the key is the parameter name and the value is the designated parameter value.  Please, be careful in the following situation: as the Silverlight Report Viewer runs on the client and the reports are on the server, there is no way to know whether or not a parameter with a given name in the dictionary exists for the specified report on the server. The match is performed on the server after the request is sent. For this reason you have to pay extra attention that the names in the dictionary and the report parameter names in the report definition match completely. This is valid for their types as well. Here is a simple example of setting report parameter values programmatically. Consider a scenario in which we want to set initial values for the cascading parameters of the Product Line Sales report:

 

 

public MainPage() 
{ 
    InitializeComponent(); 
    this.ReportViewer1.RenderBegin += new RenderBeginEventHandler(ReportViewer1_RenderBegin); 
} 
    
void ReportViewer1_RenderBegin(object sender, RenderBeginEventArgs args) 
{ 
    //single value parameter
    args.ParameterValues["ProductCategory"] = "Components";
    //multi value parameter 
    args.ParameterValues["ProductSubcategory"] = new object[] { "Brakes", "Chains" }; 
}

 

Although the values in the example are hardcoded you can take the actual values from your Silverlight UI controls. Notice that passing multiple values is achieved through an object array. In all other cases the value is set directly with its actual type.

Have in mind that this is one of the ways to accomplish the desired functionality and our ultimate goal is to provide a more sophisticated approach (e.g. Silverlight Report API) to build a report definition on the client and send it for processing on the server.

The new functionality is available in the internal build from Dec 3, 2009 and will be present in the subsequent official release. You can download it from the Latest Internal Builds page (login required).

 

11 Comments

  • Gerardo Villegas 08 Dec 2009
    Thanks for the update now I can send parameters programatly to the Silverlight ReportViewer.

    For test this functionality I did the follow steps:

    1. Uninstall the Reporting Q3 (close all Visual Studio windows before to start)
    2. Install the latest version Reporting Q3 (avalaible on 3 Dec)
    3. Replace the Telerik.Reportviewer.Silverlight.dll in "Silverlight Project"
    4. Replace the Telerik.Reporting.Service.dll in "Web Project"
    5. Replace the ReportsLibraty.dll in "Web Project"
    6. Modify the ReportService.svc in Version to in Version=3.2.9.1203 "Web Project"
    7. Replace the Telerik.Reporting.dll in "ReportsLibary Project"
    8. Add the "RenderBegin" in Silverlight ReportViewer.
    9. Test solution.

    Thanks Telerik Team!
     
    Best Regards
  • Ashley Slaughter 22 Dec 2009
    How do you access the parameters in the report class library?
  • Steve 18 Jan 2010
    @Ashley: The parameters this article refers to are params that are created and existing in the report itself. The purpose of the article is to show you how to access them from the Silverlight viewer. More info on our report parameters is available in the respective help article: Report Parameters.
  • Steve Smith 16 Feb 2010
    Been trying to get this to work with no success. I am using version 3.2.9.1211.

    BTW.. I downloaded the version referenced by the link above "Latest Internal Builds" and it was an outdated version that does not support the "RenderBegin" event.

    Anyway, I think I am doing everything as recomended but my parameter does not get passed to the server.
            void xReportViewer_RenderBegin(object sender, Telerik.ReportViewer.Silverlight.RenderBeginEventArgs args)
            {
    // I tried both
                args.ParameterValues.Add("SVClientId", 76);
    // And
                //args.ParameterValues["SVClientId"] = 76;
            }

    What am I missing? Debugging the report library I see there is a parmeter of "SVClientId" for the report but it's value is "null".
  • Magno 03 Mar 2010
    the solution:
     public partial class ReportU : Telerik.Reporting.Report  
        {  
     
            public ReportU()  
            {  
                InitializeComponent();  

                this.NeedDataSource +=new EventHandler(RankingDePotencialDeEconomia_NeedDataSource);
                this.DataSource = null;  
            }  
     
            private void ReportU_NeedDataSource(object sender, System.EventArgs e)  
            {  
                    var parameters = this.ReportParameters;
                       //.....
                this.DataSource = yourdatasource;  
            }  
        }  
  • Le_Roy 22 Aug 2010
    Thanks alot! Rly helped me :)
  • RAJ 16 May 2011
    Hi...
    Im trying to pass value to telerik report from client.. How can i achieve this.. Though following the above procedures... The reportparameters.count is always 0.. How to pass value from client to report in silverlight.....Please someone help me...
  • Vassil Petev 16 May 2011
    @RAJ: Check out the product documentation. If you are still unable to find the answer there, please, open a new support ticket and give us your code - we will help you.
  • Disappointed 14 Jul 2011
    Struggling with this too. Using MVVM. If you ask me, it seems likeTelerik provided a dud product here. A report that at first took noparameters and is now hacked to take parameters, but only when it feelslike it.
    Disappointing, what were you guys smoking?
  • Steve 14 Jul 2011
    Currently this is the only way to pass parameters from the Silverlight client to the reports on the server. So, yes there is no pure MVVM solution as the report definition does not exist on the client, however the approach works correctly and if you are having problems implementing it, please contact us via the support system.
  • neru 15 Dec 2011
    hello,
    i don't know where write my question, so i ask u here.
    I use silverlight and reporting.
    I have a datagrid with data and i would like  when i selection on (or more rows), i send this data (if possible not one by one) in my report. How can i do this.
    I started like this : In the appplication web i build my report, and after my idea it's was to do (in the report.cs) this.datasource = "data of my grid"....
    But i have to use wcf to transfer data ??

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)