ReportViewer Control in Visual Studio 2010

Introduction

ReportViewer is a freely redistributable control that enables embedding reports in applications developed using the .NET Framework. Reports are designed with drag-and-drop simplicity using Report Designer included in Visual Studio 2010.

See screenshots of some applications that have ReportViewer control embedded in them.

The ReportViewer control offers the following benefits:

  • Processes data efficiently. The reporting engine built into ReportViewer can perform operations such as filtering, sorting, grouping and aggregation.
  • Supports a variety of ways in which to present data. You can present data as lists, tables, charts and matrices (also known as crosstabs.)
  • Adds visual appeal. You can specify fonts, colors, border styles, background images etc to make your report visually appealing.
  • Enables interactivity in reports. You can have collapsible sections, document map, bookmarks, interactive sorting etc in your report.
  • Supports conditional formatting. You can embed expressions in the report to change display style dynamically based on data values.
  • Supports printing and print preview.
  • Supports export to Excel, Word and PDF formats. (Word export in Visual Studio 2010 and up.)

The control can process and render reports independently using a built-in engine ('local mode') or it can display reports that are processed and rendered on a Report Server ('remote mode').

There is a WinForms and a WebForms version of the control.

Report design in a nutshell

Defining report data sources.
Using object data sources in Windows applications and Web sites.
Add Charts to your report.
Using report parameters in local mode.
Designing master-detail reports.
Using Subreports.
What is a tablix?

Visual Studio 2005/2008 topics
Using Lists.
Adding Tables to your report.
Designing Matrix (crosstab) reports.

FAQ

  1. Q: What are the new features in ReportViewer 2010?

    A: ReportViewer 2010 supports RDL 2008 features such as Tablix, Rich Text and Gauges. Other enhancements include support for ASP.NET AJAX.

  2. Q: Is the ReportViewer control included in SQL Server?

    A: No. Report Server is a component of SQL Server, but the ReportViewer control is not. ReportViewer is only included in Visual Studio 2005/2008/2010.

  3. Q: Does SQL Server have to be installed in order to use the ReportViewer control?

    A: No. The only prerequisite of the ReportViewer control is .NET Framework.

  4. Q: Is a SQL Server license required to use the ReportViewer control?

    A: No. The ReportViewer control is freely redistributable. It can work independently of SQL Server ('local mode') and a SQL Server license is not required. In remote mode the ReportViewer control talks to a Report Server. The Report Server does require a SQL Server license.

  5. Q: Does the data for the report have to come from a SQL Server database?

    A: No. Data can come from any source. It is the host application's responsibility to collect data from whatever source it needs to come from, and supply it to the control in the form of ADO.NET DataTables or a collection of business objects. The ReportViewer control does not know or care where the data is coming from.

  6. Q: Is the ReportViewer control part of the .NET Framework?

    A: No. The ReportViewer control is distributed with Visual Studio 2005 and above, but it is not part of the .NET Framework.

  7. Q: What editions of Visual Studio 2008 include ReportViewer?

    A: ReportViewer is included in Standard and up. (i.e., all editions except Express.) An add-in is available for Visual Web Developer Express.

  8. Q: What is the difference between RDL and RDLC formats?

    A: RDL files are created by the SQL Server 2008 version of Report Designer. RDLC files are created by the Visual Studio 2008 version of Report Designer.

    RDL and RDLC formats have the same XML schema. However, in RDLC files, some values (such as query text) are allowed to be empty, which means that they are not immediately ready to be published to a Report Server. The missing values can be entered by opening the RDLC file using the SQL Server 2008 version of Report Designer. (You have to rename .rdlc to .rdl first.)

    RDL files are fully compatible with the ReportViewer control runtime. However, RDL files do not contain some information that the design-time of the ReportViewer control depends on for automatically generating data-binding code. By manually binding data, RDL files can be used in the ReportViewer control.
    See also the RDL Viewer sample program.

    Note that the ReportViewer control does not contain any logic for connecting to databases or executing queries. By separating out such logic, the ReportViewer has been made compatible with all data sources, including non-database data sources. However this means that when an RDL file is used by the ReportViewer control, the SQL related information in the RDL file is simply ignored by the control. It is the host application's responsibility to connect to databases, execute queries and supply data to the ReportViewer control in the form of ADO.NET DataTables.

  9. Q: What does the C in RDLC stand for?

    A: The C stands for Client-side processing. RDL stands for Report Definition Language.

  10. Q: Why doesn't the ReportViewer control support parameter prompting in local mode?

    A: The ReportViewer control does not prompt for parameters when in local mode. It prompts for parameters when it is connected to a Report Server.

    In local mode it does not make sense for ReportViewer to prompt for parameters. The rationale is as follows: The most common use of report parameters is to pass to queries as values of query parameters. But unlike the Report Server, the ReportViewer control does not execute queries itself. Rather, queries are executed by the host application, and the result is passed to the ReportViewer control. So the ReportViewer control does not have the opportunity to set query parameters. Applications should take advantage of the parameterization features of Visual Studio data wizards instead.

  11. Q: I installed Visual Studio 2008 and started Report Designer. I can't find the Preview tab. Where is the Preview tab that existed in SQL Server 2008 Report Designer?

    A: There are two editions of Report Designer. One comes in the Visual Studio 2008 box. The other comes in the SQL Server 2008 box. If you are using the Report Designer included in SQL Server 2008, the Preview tab is still available. If you are using the Report Designer included in Visual Studio 2008, you have to run your application in order to preview the report.

    Why is the Preview feature missing in the VS 2008 edition of Report Designer? Because the ReportViewer control does not contain any logic for connecting to databases or executing queries. Since it is your application's responsibility to supply data—and your application can supply data that originates anywhere, including objects that are internal to your application—data for previewing the report cannot be obtained without running your application.

  12. Q: Why can't I just hand an RDL file to the report control and have it do everything and show me the report?

    A: When the ReportViewer control is used in remote processing mode you can simply supply the url of the Report Server and the path to the report, and ReportViewer control will do the rest.

    In local processing mode, the ReportViewer control is designed to integrate well with the host application. That includes being able to generate reports based on business objects that are internal to your application.

    The ReportViewer control does not contain any logic for connecting to databases or executing queries. By separating out such logic, the ReportViewer has been made compatible with all kinds of data sources, including non-database data sources.

    Rather than building in the logic to connect to databases and execute queries, ReportViewer is designed to integrate well with Visual Studio data wizards and the classes they generate, such as the TableAdapter class that knows how to connect to data sources, execute queries and fetch data.

    See also the RDL Viewer sample program.

  13. Q: I dragged and dropped a field from the Data Sources window into the report. When I run the application the report only shows one row of data. How can I display all rows?

    A: To see all rows, first drag and drop a Table or a List to the report, then drag and drop the field into the Table or List.

  14. Q: I am using the WebForms ReportViewer control. ReportViewer displays the message "Report is being generated" but the report is not displayed when this progress message goes away.

    A: If you have set ReportViewer's height to a percentage, then in the .aspx file delete the line that sets doctype to xhtml. Why?

  15. Q: Does xls export require Excel to be installed?

    A: No. The xls export feature is independent of Excel. Excel is only required to view the xls file.

  16. Q: Does PDF export require an Adobe license?

    A: No. The ReportViewer control does not use any Adobe code to generate PDF files. PDF is an open format, and anyone can create PDF files without requiring a special license.

  17. Q: What are the limitations of ReportViewer control?

    A: Unlike the Report Server the ReportViewer control does not connect to databases or execute queries. Also, in local mode the only export formats available are Excel, Word and PDF. (In remote mode all formats supported by the Report Server are available.) The ReportViewer control cannot be extended by adding custom renderers or custom report items.

    Besides additional export formats, the Report Server offers better scalability, central storage, management and access control of reports, caching, subscriptions, etc.

Free downloads

WebForms and WinForms versions of the ReportViewer control.

SQL Server Express. Note: Click on Installation Options to download just the database engine, engine and management tools, or engine, management tools and "Advanced Services" which includes a free edition of Reporting Services server.

Related links

Discussion forum on MSDN

ReportViewer documentation

Tutorial

Build an IIS Log Analyzer using the WinForms ReportViewer control. Download script and sample data file.

Sample Code

Hello World

Loads data from an XML file. (Data file was previously prepared using DataSet.WriteXml() method.) Download.

Subreport

Implements master detail using a subreport. Shows how to supply data for subreports by handling the the SubreportProcessing event. Download: WinForms or ASP.NET

Drillthrough Report

Shows how to supply data for drillthrough reports by handling the the Drillthrough event. Download: WinForms or ASP.NET

Drillthro report has Subreport

If a drillthrough report has a subreport then in the Drillthrough event handler you must set a SubreportProcessing event handler for the drillthrough report. Download.

Supplying RDLs as streams

The main report and drillthrough report definitions are supplied as streams. Also shows how to examine parameters passed to a drillthrough report. Download.

Object Data Source

How to supply data using business objects. Download.

Custom Assembly

How to call AddTrustedCodeModuleInCurrentAppDomain() to allow a custom assembly to execute. Download.

Custom Assembly Accesses File

How to allow a custom assembly to access the file system. Download.

Server Report

A "hello world" application that uses the ReportViewer control in remote mode. Download.

Export to Excel

Exporting a local report to Excel format. Download.

Interactive Sort

Allow end-user to sort a table by clicking an icon in the table header. This demo is in VB. No special ReportViewer API needs to be called to use interactive sort (i.e., everything is specified in the RDL.) Download.

RSS News Reader

A simple RSS News Reader implemented using the ReportViewer control. Takes advantage of support for Object Data Sources. Download.

Master Detail with Drilldown

A master-detail report with ability to expand/collapse details. (This sample does not demo any new API calls not already demo'd by other samples on this page.) Download. Also: Master-detail-detail demo.

Print a report from a console app

You can export and print a report without displaying a GUI. Download.

Parameter prompting in local mode

This demo prompts the user for a parameter value, then filters a table in the report using the value. Data for the report comes from business objects. The business objects load their data from a CSV file. Download: WinForms or ASP.NET

Invoice Maker

Invoice Maker demo allows the user to enter data in a form and prepare an invoice. The invoice can then be printed, or exported to PDF or Excel. Almost no coding is needed, other than a couple of simple classes that have some public properties and very little else. Download.

Email a report

Add a button to your application to email a report via Outlook as a .pdf attachment. Download.

Generate RDLC dynamically - Table

Generate RDLC at run-time based on user-specified options. Download C# version or VB version. VB translation contributed by Willem van den Broek.

Generate RDLC dynamically - Matrix

Generate RDLC at run-time based on user-specified options. Download C# version.


RDL / RDLC is an open format. Its specification is available here.

RDL Viewer

View any RDL file using this sample program. The program inspects the RDL to collect data source and parameter information, prompts for parameter values, executes the query and displays the report. Download.




"You do not really understand something unless you can explain it to your grandmother." — Albert Einstein.
This is a community maintained site. Send contributions and comments to:
Copyright (c) 2005-2010