Passing Report Parameters to SubReport in VS 2010 RDLC

后端 未结 1 1795
粉色の甜心
粉色の甜心 2021-01-12 10:54

Passing Report Parameters to SubReport in VS 2010 RDLC

I\'m having some troubles defining and passing report parameters to subreports in VS 2010. In VS 2008 in the d

相关标签:
1条回答
  • 2021-01-12 11:15
    • Goto SubReport -> Report Data Pane -> Parameters and add the parameter you want to receive.

    • Goto MainReport -> Right-click SubReport -> Subreport Properties -> Parameters and add the same paramter name and pick the relevant value from the dropdown.

    • Handle the SubreportProcessing event and set the datasource for the subreport. In my case the main report datasource was of type List<Order> and the parameter was OrderID. Sample code below.

    ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);
    
    public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
    {
        var mainSource = ((LocalReport) sender).DataSources["MainDataSet1"];
        var orderId = int.Parse(e.Parameters["OrderID"].Values.First());
        var subSource = ((List<Order>)mainSource.Value).Single(o => o.OrderID == orderId).Suppliers;
        e.DataSources.Add(new ReportDataSource("SubDataSet1", subSource));
    }
    
    0 讨论(0)
提交回复
热议问题