Udostępnij za pośrednictwem


LocalReport.SubreportProcessing Event

Occurs when a subreport is processed.

Namespace: Microsoft.Reporting.WebForms
Assembly: Microsoft.ReportViewer.WebForms (in microsoft.reportviewer.webforms.dll)

Syntax

'Declaration
Public Event SubreportProcessing As SubreportProcessingEventHandler
'Usage
Dim instance As LocalReport
Dim handler As SubreportProcessingEventHandler

AddHandler instance.SubreportProcessing, handler
public event SubreportProcessingEventHandler SubreportProcessing
public:
event SubreportProcessingEventHandler^ SubreportProcessing {
    void add (SubreportProcessingEventHandler^ value);
    void remove (SubreportProcessingEventHandler^ value);
}
/** @event */
public void add_SubreportProcessing (SubreportProcessingEventHandler value)

/** @event */
public void remove_SubreportProcessing (SubreportProcessingEventHandler value)
JScript supports the use of events, but not the declaration of new ones.

Remarks

You must supply data for any data sources used in subreports. To do this, you must supply an event handler for the SubreportProcessing event.

You can examine values of parameters passed to the subreport by examining the Parameters property and supplying data corresponding to those parameter values.

If the main report has several subreports, you can examine the ReportPath property of the SubreportProcessingEventArgs class to determine which subreport is being processed and supply data for that subreport.

Please see SubreportProcessingEventArgs for a description of the arguments passed to this event handler.

Example

The following code example implements a master/detail report using subreports. The code loads a sample report that contains a subreport and sets up an event handler to handle the SubreportProcessing event. The arguments passed to the SubreportProcessing event handler include an object encapsulating the subreport. The event handler adds a data source instance to this subreport before it is rendered in the ReportViewer control.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;

public partial class _Default : System.Web.UI.Page 
{
    private DataTable orderDetailsData = null;

    private DataTable LoadOrdersData()
    {
        // Load data from XML file
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"c:\My Reports\OrderData.xml");
        return dataSet.Tables[0];
    }

    private DataTable LoadOrderDetailsData()
    {
        // Load data from XML file
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"c:\My Reports\OrderDetailData.xml");
        return dataSet.Tables[0];
    }

    void DemoSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
    {
        if (orderDetailsData == null)
            orderDetailsData = LoadOrderDetailsData();
        e.DataSources.Add(new ReportDataSource("DataSet1_OrderDetails", orderDetailsData));
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Set RDL file
            ReportViewer1.LocalReport.ReportPath = 
                @"c:\My Reports\Orders.rdlc";

            // Supply a DataTable corresponding to each report dataset
            ReportViewer1.LocalReport.DataSources.Add(
                new ReportDataSource("DataSet1_Orders", 
                    LoadOrdersData()));
    }
    // Add a handler for SubreportProcessing
    ReportViewer1.LocalReport.SubreportProcessing += new 
        SubreportProcessingEventHandler(DemoSubreportProcessingEventHandler);

    }
}
using System;
Imports System.Data
Imports Microsoft.Reporting.WebForms

Partial Class _Default
    Inherits System.Web.UI.Page

    Dim orderDetailsData As DataTable = Nothing

    Private Function LoadOrdersData() As DataTable
        Dim dataSet As New DataSet()
        dataSet.ReadXml("c:\My Reports\OrderData.xml")
        LoadOrdersData = dataSet.Tables(0)
    End Function

    Private Function LoadOrderDetailsData()
        Dim dataSet As New DataSet()
        dataSet.ReadXml("c:\My Reports\OrderDetailData.xml")
        LoadOrderDetailsData = dataSet.Tables(0)
    End Function

    Public Sub DemoSubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
        If (orderDetailsData Is Nothing) Then
            orderDetailsData = LoadOrderDetailsData()
        End If
        e.DataSources.Add(New ReportDataSource("DataSet1_OrderDetails", orderDetailsData))

    End Sub


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If (Not IsPostBack) Then

            ' Set RDL file.
            ReportViewer1.LocalReport.ReportPath = "c:\My Reports\Orders.rdlc"

            ' Supply a DataTable corresponding to each report data source.
            Dim myReportDataSource = New ReportDataSource("DataSet1_Orders", LoadOrdersData())
            ReportViewer1.LocalReport.DataSources.Add(myReportDataSource)
        End If

        'Add a handler for drillthrough.
        AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf DemoSubreportProcessingEventHandler

    End Sub

End Class

See Also

Reference

LocalReport Class
LocalReport Members
Microsoft.Reporting.WebForms Namespace