LocalReport.SubreportProcessing 事件
在处理子报表时发生。
命名空间: Microsoft.Reporting.WebForms
程序集: Microsoft.ReportViewer.WebForms(在 Microsoft.ReportViewer.WebForms.dll 中)
语法
声明
Public Event SubreportProcessing As SubreportProcessingEventHandler
用法
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);
}
member SubreportProcessing : IEvent<SubreportProcessingEventHandler,
SubreportProcessingEventArgs>
注释
SubreportProcessing 事件是针对主报表中子报表的每个实例触发的,而不是针对每个子报表定义触发的。如果报表包含同一报表定义中的多个子报表实例,则可以针对每个实例触发此事件。
您必须为子报表中使用的所有数据源提供数据。为此,您必须为 SubreportProcessing 事件提供事件处理程序。
您可以通过检查 Parameters 属性及提供对应于传递到子报表的参数值的数据来检查那些参数值。
如果主报表有数个子报表,您可以检查 SubreportProcessingEventArgs 类的 ReportPath 属性来确定正在处理哪个子报表,从而为相应子报表提供数据。
有关传递到此事件处理程序的参数说明,请参阅 SubreportProcessingEventArgs。
示例
下面的代码示例实现了使用子报表的主/详细信息报表。该代码加载包含子报表的示例报表,并设置事件处理程序来处理 SubreportProcessing 事件。传递到 SubreportProcessing 事件处理程序的参数包括包装子报表的对象。在**“ReportViewer”**控件中呈现子报表之前,事件处理程序会先向此子报表添加数据源实例。
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