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).


About the Author

Rossen Hristov

 is Senior Software Developer in Telerik XAML Team

Related Posts

Comments

Comments are disabled in preview mode.