Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

December 15, 2010

Building the Layout for a Report

Filed under: C#,Reporting,VB.NET @ 2:19 pm

This prior post provides an overview on how to include reporting in your WinForms or WebForms applications. This post details how to build the layout for a simple report.

For this simple example, the report includes a header, footer, and the list of all current customers.

The first step is to add a report file (.rdlc) to your project as defined in this prior post. Then add report items to the designer to lay out your report as detailed below.

To Add a Header:

1) Select Report | Add Header OR right-click on the designer and select Insert | Page Header.

2) Drag a Text Box or other controls from the Toolbox to the header in the designer. (View | Toolbox)

This example uses a Text Box for the report title.

3) Right-click on each control in the header and select Properties OR click on the control and use the Properties Window to set fonts, styles, and other attributes as desired.

To Add a Footer:

1) Select Report | Add Footer OR right-click on the designer and select Insert | Page Footer.

2) Drag a Text Box or other controls from the Toolbox to the footer in the designer. (View | Toolbox)

This example uses a Text Box for the print date in the bottom left corner and a second Text Box for the page number in the lower right corner.

3) Right-click on each control in the footer and select Properties OR click on the control and use the Properties Window to set fonts, styles, and other attributes as desired.

4) If you want to use an expression to populate the Text Box, right-click on a control and select Expression.

An expression allows you to define a single line of "code" that you can use to specify the contents or properties of a control. For example, you could define the current print date as an expression. Or you could set the font size as an expression.

To define a print date on the report:

image

Use Common Functions | Date & Time | Now. Double-click on Now to add it to the expression in the top pane. Be sure to close the parentheses pair.

To define a page number on the report:

image

Use Built-in Fields | PageNumber. Double-click on PageNumber to add it to the expression in the top pane. Be sure to close the parentheses pair.

To Add a Table for the Body of the Report:

1) Drag the Table control from the Toolbox to the body of the report. (View | Toolbox)

This displays a set of dialogs for setting up a data source.

  • To tie the report directly to the database, see this post.
  • To tie the report to business objects, see this post.

To skip tying the report to the data at this point, click Cancel and continue setting up the layout of the table.

2) Size and position the table (called a Tablix) as desired.

NOTE: Regardless of the number of rows that you need to display in the table, you only have to format the optional header, optional footer, and one data row. The report will repeat your styles for every data row.

3) Right-click on any cell within the table and select Properties OR click on the control and use the Properties Window to set fonts, styles, formatting and other attributes as desired.

The resulting report appears in the designer as shown below:

image

Use this technique to build the layout for any simple reports required by your application.

Enjoy!

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2019 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs