CHAPTER 9 RENDERING REPORTS FROM .NET APPLICATIONS
In this example, we will cover how to use the Windows Forms version of the Report Viewer control.
Note In the “Using the Report Server Web Service” section, we will show how to extend the application so that
it uses Report Server Web service calls to query the report server for the parameters the report can accept and the
values that are possible for each. We’ll show how to use these parameters to create dropdown lists for the users of
the Windows Forms application and then render the report.
Creating the Viewer Form
To create the viewer form in C#, you’ll start by adding a new project to your solution by taking the
following steps:
- Select File ➤ Add ➤ New Project from the menu.
- In the New Project dialog box, select Visual C# ➤ Windows ➤ Windows Forms
Application. Name it SSRS Viewer RVC. - Now that you have created the project, you’ll work with the form that will
create your report viewer: - Name the default form that was just created to ViewerRVC.cs.
- Open the ViewerRVC.cs file in design mode by double clicking the file in
Solution Explorer - Resize the blank form to around 800×600 pixels and change the text of the form
to SSRS Viewer RVC in the properties section. - Add the Report Viewer control from the Toolbox’s Reporting section to the
form. Name the control reportViewer in the properties, and anchor it to the
form’s top, bottom, left, and right. Resize the control to fill the form but leave
room at the top for a few more components.(If you do not have the report
viewer control, you may need to down load it from:
http://www.microsoft.com/download/en/details.aspx?id=6610)) - Now add a textbox, name it reportURL, and just after the textbox add three
buttons named runServer, runLocal, and getParameters. Set their Text
properties to Run Server, Run Local, and Parameters, respectively.
You should now have a form that looks like Figure 9-3.
Note In Visual Studio 2010 you will need to use a .NET framework of 3.5 or higher to get the ReportViewer
controls in the IDE. If you use anything older than this, you will not get the option of adding a viewer to your project
from the toolbox.