In the last article we saw how we can call the report from the front end using the report viewer component of Visual Studio. In real time scenarios we usually want to view a customized report with the custom parameters. In this article we are going look at how we can pass parameters to a report deployed on the report server.
Passing parameters to A Report
The following report has been deployed on the report server with two parameters – an integer and a date.
We will be passing the AddressId and ModifiedDate parameter values from the front end as below :
1. In this demonstration we will use the solution from the previous article and add the new custom code.
2. After adding labels, textboxes and button to the Basic.aspx page, set the show parameters prompt property to false in the reportviewer component :
This is an essential step as you might see the two parametric prompts when the page loads, one from the report on the report server and the second one defined on the aspx page. The above setting will hide the parametric prompt of the report deployed on the report server.
3. The below code has been defined on the view report button click event which adds the parametric values in the list whose type is report parameter and is stored in the object paralist. The paralist is converted to an Array and then given to the reportserver in order to set the values of the parameter as below :
4. The server report is refreshed from the last state of the cached data to the new set of parametric values which are now sent to the report server.
5. Consider using the calendar control from the Ajax control toolkit which ships with the .NET Framework which will give more control to the users for the date picking.
6. After clicking on the View Report button the below report is generated for the default set of values defined on the aspx page.
The sample code for this article can be downloaded here .]]>