Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Report Parameters to SubReport in VS 2010 RDLC

Tags:

c#

asp.net

rdlc

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 design view I was able to right click and define the report parameter and have it passed through.

In VS 2010 that prompt is missing. So my question is, how can I pass a value from a parent report to a subreport in VS 2010?

Additionally, this is what is shown in the Report Properties dialog inside of VS 2010:

For the time being I have defined the parameter in the subreport manually in the XML but I'm receiving an error from the main report when I attempt to pass a parameter of any type to the subreport.

The error is :

An error occurred during local report processing.

Value cannot be null. Parameter name: value

Where I do not have a parameter named value defined anywhere.

like image 223
Prodip Avatar asked Sep 12 '11 12:09

Prodip


1 Answers

  • 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));
}
like image 110
Ε Г И І И О Avatar answered Sep 23 '22 08:09

Ε Г И І И О