RDL (c) report design step by step 2: subreport

Source: Internet
Author: User

Two days ago, some netizens commented on the blog and asked to post the configuration of the subreport. Due to some other issues in the past two days, they were delayed. In addition, they were also relatively lazy, something should have been written long ago. Haha, say "sorry", and then "Thank you "!

OK. This article describes how to implement subreport IN THE subreport OF THE rdlc report.

First, let's take a look at the running results of the example in this article.


Figure 1 Main Report sample running result

The data source of the primary and sub-reports should also be two data tables with primary and sub-relationships. In this example, the order and order details of the northwind database are still used as the data source.

1. Create a Windows Application in Visual Studio 2005ProgramRdlcsr.

2. Add a data source to a project. The data source is not necessarily used to provide data for reports (of course, the operations provided by Visual Studio 2005 are very convenient ), in the report design, you can drag fields to the report. Adding a data source means adding a dataset orders to the project. XSD file. When the report data is not from a relational database (such as flat files or Web Services), we can define an XSD file as the data source for report design, in the program, refresh the report to load data.

3. Add the report rptorder. rdlc and rptorderdetail. rdlc to the project as the main report and subreport respectively.

4. Add the parameter porderid for the subreport rptorderdetail. rdlc, specify its data type as integer, and then design the layout of the subreport.


Figure 2 Layout Design of The subreport rptorderdetail. rdlc

5. design the layout shown in 3 for the main report rptorder. rdlc.


Figure 3 layout design of the main report rptorder. rdlc

6. Right-click the subreport control of the main report rptorder. rdlc and use the "properties" menu to bring up the "subreport properties" dialog box. On the "General" tab, select rptorderdetail from the subreport drop-down list. On the "Parameters" tab, in the "parameter name" column, the system automatically detects the parameter porderid of the subreport defined in step 4, and specifies the parameter value = fields in the "parameter value" column! Order ID. value.

7. In the subreport rptorderdetail. rdlc, select the table control, right-click the control menu, and choose Properties to bring up the table Properties dialog box. On the Filter tab, set the parameters in Figure 4. This is mainly to filter the detailed data of the current order in order details, of course, this step can be used in the programCode.


Figure 4 specify a filter in the subreport rptorderdetail. rdlc

Now that the report layout is complete, you need to display the report in the application and provide data to the primary and subreports respectively.

8. Add the reportviewer control rptmain to the form frmmain, and select report rptorder. rdlc from "reportviewer task" in rptmain.

9. Add the code shown in Figure 5 to the form frmmain:


Figure 5 code of the form frmmain

It can be seen that a subreportprocessing event must be added to the localreport object of the reportviewer control, which is mainly used to provide data for subreports.

Now you can run the application to view the results, as shown in figure 6.


Figure 6 example running result (no group is specified for the List)

As shown in figure 6, two orders are displayed on the same page. in actual application, we may expect that

Only one order is displayed. In this case, you can perform the following settings:

10. In the main report rptorder. in rdlc, select the list control and right-click "properties" to bring up the "List properties" dialog box. On the "General" tab, click the "Edit detail group" button to bring up the "Group and sort Attributes dialog box" and set it as shown in 7.


Figure 7 specify a group for the list and set the page display Option

In fact, the main and sub-reports are similar to the drill-down reports. If you read this article, you can refer to another article in my rdlc report Step by Step 1: drillthrough report.

Download demo

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.