How to use ReportViewer Control in Microsoft Visual Studio 2005
Using ReportViewer in your Visual Studio projects, you can create web pages
that can run and display Microsoft SQL Server 2005 Reporting Services reports.
First of all, I created a Report Server project. I created this reporting
services project by selecting the Report Server Project project type from Business Intelligence Projects.
I created a Report named Products.rdl in the Report Server Project. The
report simply listed information about the product whose id is supplied as a
parameter to the report.
The data source of the report is : = "SELECT * FROM Products WHERE ProductId
= " & Parameters!ProductId.value
In this report you will see that a parameter named ProductId has been created.
I configured the parameter as a Hidden parameter since I do not want it to be
displayed in the ReportViewer component.
I'll set the value of the ProductId report parameter by code, and I'll get
this value from the user on the web page using a textbox.
After I have created the sample report Products.rdl and ran it in the preview
pane, I deployed the report to the Report Server. For deployment I configured
the SQL Server 2005 Reporting Services instance as the TargetServer for the
The SQL Server 2005 Reporting Services is installed on my local computer as
ReportServer$Yukon and I have created a ReportsFolder named KodyazReports as a
container for sample reports.
I'm attaching the sample Business Intelligence Report project Reports to
Sample Reporting Services Report files folder where you can download it from that link.
After I have created and deployed the rdl report file to the web server, I created a web site which I have named as ReportsSite.
This is a simple ASP.NET web site with only one file the default.aspx. This
default page contains the ReportViewer control named ReportViewer1, a textbox in
order to enter the parameter named ProductId for the report and a button Button1 to run
On the Click event of the button, I set the ReportViewer1 control properties
and use ReportViewer control's methods to display the report Products.
First of all the used namespace for configuring report viewer control for
displaying a reporting services report is Microsoft.Reporting.WebForms
From the namespace Microsoft.Reporting.WebForms which is a member of
Microsoft.ReportViewer.WebForms, we use the ReportParameter class to set
parameters for the report. An array of Microsoft.Reporting.WebForms.ReportParameter
is used to pass parameter values to the report which the report viewer is
The report for the ReportViewer control is defined by the ReportServerUrl and
the ReportPath properties of ServerReport or LocalReport. If the report is
located on a Report Server the ReportViewer1.ServerReport class is used. But if
the report is processed and rendered locally without connecting to a Report
Server than the ReportViewer1.LocalReport class is going to be used.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://localhost/reportServer$Yukon")
ReportViewer1.ServerReport.ReportPath = "/KodyazReports/Products"
Dim params(0) As Microsoft.Reporting.WebForms.ReportParameter
Dim p As Microsoft.Reporting.WebForms.ReportParameter
p = New Microsoft.Reporting.WebForms.ReportParameter("ProductId",
params(0) = p
Below you can see the Product report is displayed within web form default.aspx
after value 7 is supplied as the ProductId parameter and the "Run Report" button
You can see that the Export to other formats functionality is still available
and can be used by users on the web.