CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Simple Report With Group Headers

This example shows how to create a simple report. The Grid form in this example contains a list of employees whereby each employee belongs to a department. The Grid lists the employees (: ID, Name and Title) in such a manner that a Header row indicates the department of the employee records appearing in the rows below it.
2John SmithManager
5Rob McDonaldManager
1Bob KuchSr. Developer
3Pablo SanchezDeveloper
7David SnyderDeveloper
6Stefan FeySupport

For ASP, PHP, Perl, ColdFusion

Make sure that you are in HTML mode then:

  1. Modify the HTML content as shown below. In this case, the code in blue has been added to the existing HTML code for the Grid.
  2. <!-- BEGIN Row -->
      <!-- BEGIN Label department_name -->
        <td bgcolor="#336699" colspan="3"><font color="White">{department_name}</font></td>
      <!-- END Label department_name -->
        <td class="ClearDataTD">{Label1} </td>
        <td class="ClearDataTD">{emp_name} </td>
        <td class="ClearDataTD">{title} </td>
      <!-- END Row --
  3. In the Before Show Row event of the grid, add the following code:


Dim DepName
Function departments_BeforeShowRow(Sender)

  If DepName = departments.department_name.Value Then
     departments.department_name.Visible = False
     departments.department_name.Visible = True
     DepName = departments.department_name.Value
   End  If 

End Function


function departments_BeforeShowRow(& $sender) {
global $DepName;
global $departments;

  if ($DepName == $departments->department_name->GetValue()) {
     $departments->department_name->Visible = False;
  } else {
     $departments->department_name->Visible = True;
     $DepName = $departments->department_name->GetValue();



sub departments_BeforeShowRow() {

  if ($DepName eq $departments->{department_name}->GetValue()) {
     $departments->{department_name}->{Visible} = 0;
  } else {
     $departments->{department_name}->{Visible} = 1;
     $DepName = $departments->{department_name}->GetValue();



<!---departments_BeforeShowRow --->
  <CFPARAM Name="DepName" Default="">
  <CFIF DepName EQ flddepartment_name>
    <CFSET hideDepartment_name= True>
    <CFSET hideDepartment_name=False>
    <CFSET DepName=flddepartment_name>



  String depName = (String) e.getPage().getRequest().getAttribute("departmentname");
  if ( depName == null ) {
    depName = "";
  if (depName.equals(e.getGrid().getControl("department_name").getValue()) ) {
  } else {
    e.getPage().getRequest().setAttribute("departmentname", e.getGrid().getControl("department_name").getValue());


  1. If you are using C# or VB.Net, modify the HTML as follows:
  2. <!-- BEGIN Row -->
      <tr id="departmentsNameTR" runat="server">
        <td bgcolor="#336699" colspan="3"><font color="White">{department_name}</font></td>
        <td class="ClearDataTD">{Label1} </td>
        <td class="ClearDataTD">{emp_name} </td>
        <td class="ClearDataTD">{title} </td>
      <!-- END Row -->
  3. Then within the code for the page, add the variable called DepName below the section that ends with the text 'End Forms Definition


'End Forms Definition 
  Dim DepName As String 


//End Forms Definition 
 protected String DepName;


  • Then add the following code in the Before Show Row event of the grid.
  • VB.Net

      If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim departmentsNameTR As Control = e.Item.FindControl("departmentsNameTR")
        If DepName = DataItem.department_name.Value Then
           departmentsNameTR.Visible = False
           departmentsNameTR.Visible = True
           DepName = DataItem.department_name.Value
        End If 
      End If


      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
        Control departmentsNameTR = e.Item.FindControl("departmentsNameTR");
        if (DepName == DataItem.department_name.Value.ToString()) {
           departmentsNameTR.Visible = false;
        } else {
           departmentsNameTR.Visible = true;
           DepName = DataItem.department_name.Value.ToString();

    See also:

    Before Show Row event, Grid form

    On-line, printable versions and updates