ComponentOne GridView for ASP.NET AJAX: GridView for ASP.NET AJAX Task-Based Help > Using Aggregates and Grouping > Grouping Properties

Grouping Properties

The example below shows a typical grid and how you would set the GroupInfo and Aggregate properties for the columns.

Note: This example uses the Grouping sample and an Access database, WebGridDemo.MDB, provided with C1GridView.

To group orders by year and show the sales totals, set the following properties:

1.   The DataSource should be sorted by OrderYear (for example, 'SELECT OrderDate, YEAR(OrderDate) AS OrderYear, Country, Salesperson, OrderID, ExtendedPrice FROM Invoices ORDER BY YEAR(OrderDate) DESC, Country, Salesperson, OrderID, ExtendedPrice DESC').

2.   The GroupInfo property of the OrderYear column should be set as follows (these properties can be set at design time by choosing Grouping from the Property builder):

      Set the Position property to Header (group rows will appear before the data).

      Set the HeaderText property to "Orders in <i>{0}</i>". (This is the text on group header rows; {0} is replaced with the value being grouped on).

      Expand the HeaderStyle property and set it. (This is the style for the group header rows; you will usually set at least the HeaderStyle.BackColor).

3.   The Aggregate property of the ExtendedPrice column should be set to Sum. This will cause the grid to add the sales for each group and display the aggregate value in the group header (and footer) rows. To set this property:

      Select Columns from the Property builder.

      Choose ExtendedPrice from the list of Selected columns.

      Set the Aggregate property to Sum.

4.   To make the grid appear neatly and organized, you can use the GroupIndent property to indent each group a specific number of points or pixels. To set this property:

      Click the C1GridView control once to select it.

      In the Properties window, set GroupIndent to 15px or the desired amount of space.

You can have as many group and aggregate columns as you want. For example, you could show totals for sales, and group data by country, salesperson, and order number.

* Sample Project Available

For the complete sample, see the Grouping sample located on the ComponentOne HelpCentral Sample page.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.