Skip to main content
Tab

ASPxGridView.GroupBy(GridViewColumn) Method

Groups data by the values of the specified data column.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public int GroupBy(
    GridViewColumn column
)

Parameters

Name Type Description
column GridViewColumn

A grid column.

Returns

Type Description
Int32

The column’s grouping level.

Remarks

When you call the server-side GroupBy(GridViewColumn) method, the control keeps the previous grouping and adds the column to the collection of grouped columns.

To define the column’s grouping level, use the GroupIndex property. To clear grouping applied to a particular column on the server side, call the ASPxGridView.UnGroup or GridViewDataColumn.UnGroup method.

For more information on grouping in the grid, refer to the following topic: ASPxGridView - Group Data.

Example

Run Demo: ASPxGridView - Grouping Data

<dx:ASPxComboBox runat="server" ID="cbFields" ValueType="System.Int32" SelectedIndex="0" Caption="Group by">
    <Items>
        <dx:ListEditItem Text="Country" Value="0" />
        <dx:ListEditItem Text="Country, City" Value="1" />
        <dx:ListEditItem Text="Company Name" Value="2" />
    </Items>
    <ClientSideEvents SelectedIndexChanged="OnSelectedIndexChanged" />
</dx:ASPxComboBox>

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" AutoGenerateColumns="false"
    KeyFieldName="CustomerID" OnCustomCallback="grid_CustomCallback">
    <Columns>
        <dx:GridViewDataColumn FieldName="ContactName" />
        <dx:GridViewDataColumn FieldName="CompanyName" />
        <dx:GridViewDataColumn FieldName="City" />
        <dx:GridViewDataColumn FieldName="Region" />
        <dx:GridViewDataColumn FieldName="Country" />
    </Columns>
    <Settings ShowGroupPanel="true" />
</dx:ASPxGridView>
function OnSelectedIndexChanged(s, e) {
    grid.PerformCallback(s.GetValue);
}
protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
     ApplyLayout(Int32.Parse(e.Parameters));
}

void ApplyLayout(int layoutIndex) {
    grid.BeginUpdate();
    try {
        grid.ClearSort();
        switch(layoutIndex) {
            case 0:
                grid.GroupBy(grid.Columns["Country"]);
                break;
            case 1:
                grid.GroupBy(grid.Columns["Country"]);
                grid.GroupBy(grid.Columns["City"]);
                break;
            case 2:
                grid.GroupBy(grid.Columns["CompanyName"]);
                break;
        }
    } finally {
        grid.EndUpdate();
    }
    grid.ExpandAll();
} 
See Also