Udostępnij za pośrednictwem


Configuring Subreports and Drillthrough Reports (Visual Studio Report Designer)

You can use subreports and drillthrough reports to link related reports together.

  • A subreport is a control embedded inside the body of a parent report. Conceptually, a subreport is similar to a frame in a Web page that provides a container for other Web page content. The subreport is rendered inside the parent report that contains it. Both reports are processed and displayed simultaneously.

  • A drillthrough report opens as the result of a drillthrough action set on a report item. This action typically opens a related report or the same report with different parameters in the same space as the parent report. The drillthrough report is usually related to the parent report through data. A common example of a drillthrough report might be a Monthly Sales report that contains links to individual sales orders for that month. When you click a drillthrough link, the parent report is replaced with a different report that provides the supporting detail.

Both drillthrough reports and subreports support the notion of parent report and child report. To relate the reports, you must create report parameters that can be used to pass data that establishes the relationship. To link the reports at run time, you must write code that supports the connection. When deploying related reports, be sure that the client report definition (.rdlc) files are stored together in the same folder on the file system.

The following events include sample code that shows how to implement subreports and drillthrough actions for the ReportViewer control:

For information about including drilldown interactivity to your report, see How to: Hide or Define Toggle Visibility on a Report Item (Visual Studio Report Designer).

Adding Subreports

A subreport and its parent report can be related through shared parameters. You must add parameters to each report. The parameters must be configured before you add a subreport to the parent report. When you add the subreport, you set up the parent report to pass parameters to the subreport.

To add a subreport

  1. Open the client report definition (.rdlc) file in graphical design mode.

  2. In the Toolbox, click Subreport.

  3. On the design surface, drag a box to the size you want the subreport to be. Alternatively, click the design surface to create a subreport of fixed size.

    Note

    If the subreport exists in the project, you can drag the report from Solution Explorer onto the design surface to create a subreport.

  4. Right-click the subreport and then click Properties.

  5. In Subreport, select the report that you want to appear in the subreport area.

  6. On the Parameters tab, do the following:

    • In Parameter Name, type the name of a parameter in the subreport. This name must match a report parameter in the report named in the ReportName property.

    • In Parameter Value, type a value to pass to the subreport. This value can be static text or an expression pointing to a field or other object in the parent report.

  7. Repeat step 2 to add additional parameters to pass to the subreport.

Note

All parameters that are required by the subreport must be included in the Parameters list. If a required parameter is missing, the subreport is not displayed correctly within the parent report.

To supply data for subreports, your application must handle the SubreportProcessing event of the LocalReport object. One of the arguments passed to the SubreportProcessing event handler method is SubreportProcessingEventArgs. In the event handler, the application may examine the values of parameters passed to the subreport using the Parameters property of SubreportProcessingEventArgs. The application must then supply the data for the subreport using the DataSources property of SubreportProcessingEventArgs.

Configuring Drillthrough Reports

You can configure drillthrough reports by defining drillthrough actions that provide navigation from a parent report to a secondary report that contains supporting data.

A drillthrough report typically contains parameters that are passed to it by the parent report. In the sales summary report example, the drillthrough report contains a parameter that takes the order as a value. The summary report includes a drillthrough report link for each order number, which opens the target detail report when clicked and passes the order ID to it.

Any report that is stored on the report server can be a drillthrough report. You can add drillthrough links only to text boxes and images.

  1. Open the client report definition (.rdlc) file in graphical design mode.

  2. Right-click the text box or image to which you want to add a link and then click Properties.

  3. On the Navigation tab, select Jump to Report.

  4. Type or select a report name. The report must be a .rdlc file that is part of the same project.

  5. To set parameters to pass to the drillthrough report, click Parameters, and then do the following:

    • In Parameter Name, type the names of the report parameters in the drillthrough report.

      Note

      The names in the parameter list must match the expected parameters in the target report exactly. If the names do not match, or if an expected parameter is not listed, the drillthrough report fails.

    • In Parameter Value, type or select the values to pass to the parameters in the drillthrough report.

      Note

      Values can contain an expression that evaluates to a value to pass to the report parameter. The expressions in the value list include the field list for the current report.

To supply data for drillthrough reports, your application must handle the Drillthrough event of the ReportViewer object. One of the arguments passed to the Drillthrough event hander method is DrillthroughEventArgs. DrillThroughEventArgs has a Report property which represents the drillthrough report. In the event handler, the host application may examine the values of parameters passed to the drill-through report by calling the GetParameters() method on the drillthrough report. The host application must then supply the data for the drillthrough report using the DataSources property of the drillthrough report.

See Also

Concepts

Defining Report Parameters in a Report (Visual Studio Report Designer)
Adding Interactivity, Visibility, and Navigation to a Report (Visual Studio Report Designer)

Other Resources

Samples and Walkthroughs