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
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));
}