Gets or sets a value that specifies which properties are used for grouping the retrieved data.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
You use the Name, all the records in the query that have the same Name property value are returned as a single consolidated record.property to specify which properties are used for consolidating data records that have the same values. For example, if you set the property to
You can assign more than one property to the Name and then Category, set the property to new(Name, Category).property by enclosing all the properties in the new function and separating each property by using a comma. For example, to group by the properties
The values in the property that are used for grouping are returned through a generated property named Key. You include the Key property in the Select property to retrieve the grouped values. You can set the Key property to an alias by using the As keyword, but you are not required to use an alias. For example, you might set the property to a property named Category. You can retrieve the consolidated values from the Category property by setting the Select property to new(Key As ProductCategory).
You can access the individual records in a grouping by including the It property in the Select property. The It property contains a collection of records that share a value in the grouped property. You can iterate over the It property to retrieve the individual records.
Theproperty is often used with aggregation methods. You can use the following aggregate methods:
For more information, see NIB: LinqDataSource Web Server Control Overview and How to: Group and Aggregate Data Using the LinqDataSource Control.
The following example shows a LinqDataSource control that groups the returned data by a property named Category. It returns the shared values and calculates the average price for the grouped records.
The following example shows a LinqDataSource control that is configured to group by two columns. The Key property references an object that has two properties, ProductCategory and Color. The object represented by It is renamed Products. The renamed Products object contains a collection of the individual records in a grouping, and each instance contains all the columns from the Products table.
The following example shows two ListView controls for displaying the data from the LinqDataSource control in the previous example. One ListView control displays the grouped data and the other ListView control displays the individual names of products that belong to that group. The nested data-bound control's DataSource property is set to Products, which is the alias for the It object.
Available since 3.5