Creating Sub Reports Dynamically
Subreports can be created dynamically. For example, a subreport can be loaded into a main report via code. The interesting part of this task is in the Page_Load event. The following source shows how to do this:
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
' Load the main report definition
Me.C1WebReport1.Report.ReportDefinition = Me.C1Report1.ReportDefinition
' OR you could load it this way:
' Me.C1WebReport1.Report = Me.C1Report1
' Now insert the subreport.
Dim f As C1.C1Report.Field = Me.C1WebReport1.Report.Fields("subreportHolder")
f.Subreport = Me.C1Report2
' Set the subreport field's Text property to act as a filter
f.Text = """CategoryID = "" & CategoryID"
' Optionally, hide the subreport header
f.Subreport.Sections.Header.Visible = False
End Sub
• C#
private void Page_Load(object sender, System.EventArgs e)
{
// Load the main report definition
this.c1WebReport1.Report.ReportDefinition =
this.c1Report1.ReportDefinition;
// OR you could load it this way:
// this.c1WebReport1.Report = this.c1Report1;
// Now insert the subreport
C1.C1Report.Field f =
this.c1WebReport1.Report.Fields["subreportHolder"];
f.Subreport = this.c1Report2;
// Set the subreport field's Text property to act as a filter
f.Text = "\"CategoryID = \" & CategoryID";
// Optionally, hide the subreport header
f.Subreport.Sections.Header.Visible = false;
}
|