dna86
dna86

Reputation: 407

Setting Telerik Report Parameters from Silverlight ReportViewer application

I have a Silverlight application that has a Telerik ReportViewer contained in it. I want to select a report and the parameter values in code and pass this information to the report viewer. Does anyone know how to do this? All I can find is setting the Report property to the name of the report.

Upvotes: 0

Views: 2611

Answers (1)

Mike Wiese
Mike Wiese

Reputation: 76

If you define a handler for the ReportViewer's RenderBegin event, you receive a RenderBeginEventArgs parameter with an empty NameValueDictionary property called ParameterValues.

You can Add {name, value} pairs to this collection and they seem to finish up in the Parameters collection of the Report.

For example, I have two report parameters named "InputElementID" and "ReportPeriod". My RenderBegin handler looks something like the following:

    private void ReportViewer_RenderBegin(object sender, Telerik.ReportViewer.Silverlight.RenderBeginEventArgs args)
    {
        args.ParameterValues.Add("InputElementID", this.elementId);
        args.ParameterValues.Add("ReportPeriod", "fortnight");
    }

But this will raise another issue: How do you get the report to re-render itself with new parameters in response to user interaction? For example, in my case I had a master-detail page set up, with a RadTreeListView on the left and my ReportViewer on the right. I needed to get my ReportViewer to re-compute itself every time the selected item changed.

The ReportViewer has no methods to force a re-render. And setting its Report property does nothing, as the Report string will be the same every time if all you're changing is the parameter.

My hacky solution was to set the ReportServiceUri property when I wanted to force a change.

// No change, just forces the ReportViewer to re-render itself
this.ReportViewer.ReportServiceUri = new Uri("../ReportService.svc", UriKind.RelativeOrAbsolute);

There must surely be a better way, but this should get you going.

Upvotes: 3

Related Questions