Hello Reggie Gardner,
To drive data into subreports there are three ways:
1. Using Report Filters.
Please refer to the Product Line Sales Report example (Telerik | Reporting | Examples | C# Solution):
- In the report which will serve as sub report (some times named Slave Report):
- Edit DataSource property to connect report to the data;
- Edit ReportParameters property to create proper parameters;
- Edit Fileters property to create data source filtering criteria.
- In the report which will serve as master report:
- Add Subreport item and assign it's ReportSource property to the report described above;
- Edit subreport's Parameters property to bind parameters of slave report to data fields of master report.
- First preview the TopEmployees report and initialization of it's DataSource, Filters and ReportParameters properties;
- Then look how the master report (ProductLineSales) drives the TopEmployees through subreport's Parameters property.
2. Using NeedDataSource event handler.
In Master report opened in report designer select the Subreport item and create a NeedDataSource event handler. In this event handler we are initializing the sub report's DataSource property. We can use command parameters to filter the data:
|Telerik.Reporting.Processing.ReportItemBase item = sender as Telerik.Reporting.Processing.ReportItemBase; |
|DataRowView dataRow = (DataRowView)item.DataItem; |
|string commandText = @"SELECT id, name, invoiceID FROM theTable WHERE groupID=@parameterID"; |
|SqlDataAdapter adapter = new SqlDataAdapter(commandText, connectionString); |
|adapter.SelectCommand.Parameters.AddWithValue("@parameterID", dataItem["InvoiceID"]); |
|this.DataSource = adapter; |
where InvoiceID is real column name from master report's data source.
In already mentioned Product Line Sales Report example you can preview chart1_NeedDataSource method of ProductLineSales report where we initialized the chat's data source in same fashion.
3. Using ItemDataBinding
- Create Slave report and connect its DataSource through SqlDataAdapter with command parameter as demonstrated here and expose the parameter through public property;
Please preview attached 107491B sample solution.
- In Master report opened in report designer select the Subreport item and create a ItemDataBinding event handler. In this event handler we are initializing the sub report's command parameter.
About using one DataSet object as data source for master and sub reports. Probably the empty reports in your case are result of not filled DataSet object. Please preview attached 107491A
sample solution where three-level hierarchy is displayed.
Note: refer to Performance Considerations
before you decide which method to implement in your case.
Please refer following help-topics for more information as well: Adding a Data Source Programmatically
, Filtering Report Data
, Edit Filter Dialog
, Creating Master-Detail Reports Using SubReports
, Display Hierarchical Data with SubReports
I hope this information helps.
the Telerik team