Section 8.2. Report Viewer Control

8.2. Report Viewer Control

The report viewer control is a freely distributable control that lets you embed Reporting Services functionality into a .NET application. The control is called ReportViewer, ships with Visual Studio 2005, and is located in the Data section of the Toolbox in the Visual Studio 2005 IDE.

Follow these steps to build an example that uses the report viewer control.

  1. Launch Visual Studio 2005.

  2. Create a new C# Windows application. Select File New Project from the main menu. Select Visual C# Windows project type, and the Windows Application template. Name the application

    Open the form and give it a meaningful caption. Right-click Form1.cs in the Solution Explorer pane and select Open from the context menu. Set its Text property = Report Viewer Control Example.

  3. Drag the ReportViewer control from the Toolbox onto Form1. The ReportViewer control menu prompts you to either Choose Report from a drop-down list or Design a new report. Click Design a new report to bring up Report Designer. Select <Server Report>, and you are prompted for the Report Server Url and the Report Path that together specify an existing report.

    Set Report Server Url = http://localhost/reportserver and Report Path = /AdventureWorks Sample Reports/Company Sales.

  4. Make the form a bit larger so that the Report Viewer control fits within it.

  5. Run the applicationthe resulting output is shown in the following figure.

You can control and change the report at runtime by modifying the properties of the control's ServerReport objectexposed through the ServerReport property.

SQL Server 2005 Reporting Essentials
SQL Server 2005 Reporting Essentials
ISBN: 735617880
Year: 2007
Pages: 31 © 2008-2017.
If you may any questions please contact us: