更新时间:2023-02-24 13:14:15
我已经找到了将参数传递给子报表的子报表的方法:
I have found the way to pass parameters to subreport of subreport:
public partial class FormReportViewerAsnDetailed : Form
{
private readonly int PoID;
public FormReportViewerAsnDetailed(int PoID)
{
this.PoID = PoID;
InitializeComponent();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", bindingSource1));
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", bindingSource2));
reportViewer1.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing;
}
private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
if (e.Parameters.Any(k => k.Name == "AsnID")) //is it asn subreport?
{
var asn = int.Parse(e.Parameters["AsnID"].Values.First());
asn_Details_ReportTableAdapter1.Fill(viewAsnDetailsDataSet1.Asn_Details_Report, asn);
e.DataSources.Add(new ReportDataSource("DataSet2",
new BindingSource(viewAsnDetailsDataSet1, "Asn_Details_Report")));
inbound_By_AsnTableAdapter1.Fill(inboundsReportDataSet1.Inbound_By_Asn, asn);
e.DataSources.Add(new ReportDataSource("DataSet1",
new BindingSource(inboundsReportDataSet1, "Inbound_By_Asn")));
}
else // subreport of subreport
{
inbound_Items_ReportTableAdapter1.Fill(inboundItemsReportDataSet1.Inbound_Items_Report,
int.Parse(e.Parameters["InboundID"].Values.First()));
BindingSource src = new BindingSource(inboundItemsReportDataSet1, "Inbound_Items_Report");
e.DataSources.Add(new ReportDataSource("DataSet1", src));
}
}
private void FormReportViewer_Load(object sender, EventArgs e)
{
this.purchase_Order_Details_ReportTableAdapter1.Fill(
purchaseOrderDetialsReport1.Purchase_Order_Details_Report, PoID);
asn_Select_By_POTableAdapter1.Fill(asnDetailedList1.Asn_Select_By_PO, PoID);
reportViewer1.LocalReport.SetParameters(new ReportParameter("po", PoID.ToString()));
this.reportViewer1.RefreshReport();
}
}
这里,我有两个用于主报告的数据集.它们在构造函数方法中传递,并与主报表参数一起填充到加载方法中.
Here, I have two datasets for the master report. They are passed in the constructor method, and filled in the load method along with the master report parameter.
在子报表处理中,需要发现谁在调用子报表:subreport 还是 subreport-of-subreport?然后你需要将数据源传递给每一个.
In subreport processing, you need to discover who is subreport calling: subreport or subreport-of-subreport? Then you need to pass datasources to each one.