Crystal report groups can be either static or dynamic, depending upon its requirement. We can define a Static group on fields and its values in the report. Where as a dynamic group or groups is a pre-defined Formula Field and we pass values using a Parameter define in the Parameter Field.
Talking about passing parameters, you must be eager to know how we can pass parameters to a Crystal Report in Asp.Net. Believe me it is very simple.
Assuming that you already have designed the report using Crystal Reports; we will straight away go to the Grouping part. If you are still puzzled about how to create a Crystal Report from the beginning, then I recommend you read this article on creating your first Crystal Report in Asp.Net.
As usual, I will use the Employee details table in my report for grouping. It has five columns and the dynamic grouping will be by either Designation or Department.
Create a Parameter in Crystal Report
Open the report in crystal report (for demo we will use Employee.rpt), and in the Field Explorer section, right click Parameter Fields and create a New parameter. Name the String parameter as ParaGroup. We will not define any Default Values and instead pass the values from an application.
The Formula
Once we are done with the parameter, we will create a formula in which the parameter will be used to set conditions for grouping.
if {?ParaGroup} = … then
This formula will be used in the Group By field using the Group Expert. Right click the Formula Fields under Field Explorer and click the New button. Name the formula as DynamicGroup and set conditions using the Parameter we earlier created.
Crystal Report Group
Create a group by right clicking the report and choose Insert -> Group… which will open an Insert Group window. Select the DynamicGroup formula from the dropdown list.
Finally, in your application set options for passing the parameters for the group we just defined, and run the application to preview the report.