Creating Client Report Definition (.rdlc) Files

The ReportViewer control supports a local processing mode that allows you to run client report definition (.rdlc) files using the built-in processing capability of the control. The client reports that you run in local processing mode can be easily created in your application project. There are four approaches to creating the report:

  • You can create a new client report definition (.rdlc) file using the Report Wizard.

  • You can create a new client report definition (.rdlc) file in Visual Studio.

  • You can convert an existing report definition (.rdl) file to the client report definition (.rdlc) file format that is used in local processing mode.

  • You can generate a report definition programmatically.

To use an existing report definition, add a report item to the application project. When you select Add a New Item from the Project menu, you can choose Report template to build a report layout from a blank report. To create a new report, click Design a new report when configuring the ReportViewer control. This opens a blank report.

How to Create and Preview a Local Report

  1. In Microsoft Visual Studio 2008, open the application project or Web site.

  2. Create the data sources you want to use. You can use data tables or business objects defined in datasets that are available in the project. For more information, see Creating Data Sources for a Report.

  3. Create a report definition (.rdlc) file to use in your project.

  4. Define a report layout by adding tables, text boxes, matrices, lists or charts from the Toolbox to the blank report. These items are called data regions. Data regions are bound to data sources. Specifically, you map each cell in a data region to a field in your data source. For more information, see Adding Data Regions to a Report (Visual Studio Report Designer).

  5. Finish the report by adding style, formatting, images, borders, headers, footers, sorting, and other report functionality. For more information, see Defining a Report Layout (Visual Studio Report Designer).

  6. Select the form or page that will contain the control.

  7. In graphical design mode, add a ReportViewer control to the Web page or form. The ReportViewer control is in the Data section of the Toolbox. For more information, see Adding and Configuring the ReportViewer Controls.

  8. Size and position the control on the page or form.

  9. In the ReportViewer Tasks Smart tags panel, select the client report definition (.rdlc) file you created to bind the report to the control. For more information about opening the Smart tags panel, see Using the ReportViewer Tasks Smart Tags Panel.

To preview the report, you can build or deploy the application. You can only preview a report by running it in a ReportViewer control. There is no separate preview mode just for the .rdlc file. Note that you can open and edit the report definition at any time, and then build or deploy the application to check the results.

Adding a New Report Item to a Project

When you add a new report item to a project, a blank report is created and a Report.rdlc file is added to the project. The report definition opens in graphical design mode. The report object namespace is added to the project and the available report controls are added to the toolbox.

Adding Report Items to a Report

You can easily create simple reports by dragging report items (for example, text boxes, tables, charts, and images) onto a report design surface and setting properties on those items.

A more complex report might include parameters and expressions that you use to customize the report output. For example, to get a market analysis report for a particular stock, you must add a parameter to the report to specify the stock symbol. You can provide a user interface in your application that collects a parameter value from the user. Parameters can be passed through to the query to more precisely specify data selection criteria, or can be used to filter a result set so that only a portion of the result set is displayed in the report. Parameter values can be predefined and passed in by your application, or specified by the user before executing the report.

Expressions, which are always written in Microsoft Visual Basic, are used to aggregate data or perform conditional formatting. Reports can also include custom code. You can embed custom code within your report, or call methods on a custom assembly that is part of your application. In contrast with expressions, custom code can be written in other languages besides Visual Basic.

See Also

Concepts

Using the ReportViewer Tasks Smart Tags Panel
Creating Data Sources for a Report
Defining a Report Layout (Visual Studio Report Designer)
Report Overview (Visual Studio)
Deploying Reports and ReportViewer Controls
Adding and Configuring the ReportViewer Controls
Creating Client Report Definitions Using the Visual Studio Report Wizard

Other Resources

Samples and Walkthroughs