A SubReport is a report that is inserted in another report. Subreports are useful when you want to combine several reports into one. In C1Report, creating a Subreport is very simple. To know, how to create Subreports, you can read this Documentation link. Now, there might be certain scenarios where you would like to customize the way how the Subreports appear in the final output. In this Blog, we are covering the following two scenarios.
*** Display Subreports conditionally
This can be done only using VBScript editor of C1ReportDesigner. We need to add the desired script-code into the OnPrint property of Detail section of the report. In our blog implementation, we will handle the custom display of Subreports on the basis of the field value in the Main Report.
This implementation toggles the visibility of the SubReports on the basis of a field value in the Main report. That is, if there are multiple Subreports, only the related Subreport is displayed and rest of the reports are hidden. To do this, follow the mentioned steps :
str=VehicleName
Field2.Text=str
If str="Car" then
CarSubReport.Visible= True
BikeSubReport.Visible= False
BoatSubReport.Visible= False
Elseif str="Boat" then
BoatSubReport.Visible= True
CarSubReport.Visible= False
BikeSubReport.Visible= False
Elseif str="Bike" then
BikeSubReport.Visible= True
CarSubReport.Visible= False
BoatSubReport.Visible= False
Endif
In case, you want to display different number of SubReports on the main report, follow the under mentioned steps :
str=Number
If str="1" then
CarSubReport.Visible= True
BikeSubReport.Visible= False
BoatSubReport.Visible= False
Elseif str="2" then
CarSubReport.Visible= True
BikeSubReport.Visible= True
BoatSubReport.Visible= False
Elseif str="3" then
CarSubReport.Visible= True
BikeSubReport.Visible= True
BoatSubReport.Visible= True
Endif
Refer to the attached report xml for the complete implementation. Download XML