ActiveReports allows Section Reports to contain any number of child reports using the Subreport control. Child reports, or subreports, are executed each time the parent section (i.e. the section in which the Subreport control is placed) is processed. This tutorial illustrates how to modify the subreport record source from the data in the parent report to retrieve the correct information.
SQL Query |
Copy Code
|
---|---|
SELECT * FROM Categories |
Property Name | Property Value |
---|---|
Name | lblProductsbyCategory |
Text | Products by Category |
Property Name | Property Value |
---|---|
TextBox1 | |
Name | txtCategoryID1 |
Data Field | CategoryID |
Visible | True |
TextBox2 | |
Name | txtCategoryName1 |
Data Field | CategoryName |
Label1 | |
Name | lblCategoryName |
Text | CategoryName: |
Label2 | |
Name | lblProducts |
Text | Products: |
Subreport | |
Name | SubReport1 |
Property Name | Property Value |
---|---|
CanShrink | True |
BackColor | AliceBlue |
Property Name | Property Value |
---|---|
DataField | ProductName |
Name | txtProductName |
Text | Product Name |
Property Name | Property Value |
---|---|
TextBox1 | |
DataField | ProductName |
Name | txtProductName |
TextBox2 | |
DataField | UnitPrice |
Name | txtUnitPrice |
OutputFormat | $#,##0.00 (or select Currency in the dialog) |
VB Code:
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. |
Copy Code
|
---|---|
Private rpt As rptSub Private childDataSource As New GrapeCity.ActiveReports.Data.OleDBDataSource() |
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
rpt = New rptSub()
|
C# Code:
The following example shows what the code for the method looks like.
C# code. Paste JUST ABOVE the ReportStart event. |
Copy Code
|
---|---|
private rptSub rpt; private GrapeCity.ActiveReports.Data.OleDBDataSource childDataSource = new GrapeCity.ActiveReports.Data.OleDBDataSource(); |
C# code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
rpt = new rptSub();
|
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste INSIDE the Format event. Copy Code childDataSource.ConnectionString = CType(Me.DataSource, GrapeCity.ActiveReports.Data.OleDBDataSource).ConnectionString childDataSource.SQL = "SELECT * FROM Products WHERE CategoryID = " + Me.txtCategoryID1.Value.ToString rpt.DataSource = childDataSource SubReport1.Report = rpt
C# code. Paste INSIDE the Format event. Copy Code childDataSource.ConnectionString = ((GrapeCity.ActiveReports.Data.OleDBDataSource)this.DataSource).ConnectionString; childDataSource.SQL = "SELECT * FROM Products WHERE CategoryID = " + this.txtCategoryID1.Value.ToString(); rpt.DataSource = childDataSource; SubReport1.Report = rpt;
Click the preview tab to view the report at design time.