Skip to main content
A newer version of this page is available. .
Tab

ASPxGridView.IsGroupRow(Int32) Method

Indicates whether the specified row is the group row.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

NuGet Package: DevExpress.Web

Declaration

public bool IsGroupRow(
    int visibleIndex
)

Parameters

Name Type Description
visibleIndex Int32

An integer value that identifies the row by its visible index.

Returns

Type Description
Boolean

true if the specified row is the group row; otherwise, false.

Remarks

To learn more, see Grouping Overview.

Example

This example shows how you can numerate grid rows using an unbound column. If the grid is not grouped by columns, rows are numerated starting from the first to the last. If a grid is grouped by a column, rows are numerated starting from the first row to the last row in a group.

View Example

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using System.Data;

public partial class _Default : System.Web.UI.Page {
    private List<int> groupIndexes = new List<int>();
    int rowInGroupNumber = 1;
    bool isFirstDisplayedRow = true;

    private bool IsGridUngrouped { get { return groupIndexes.Count == 0; } }

    protected void grid_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) {
        if (e.Column.Name != "RowNumber")
            return;

        ASPxGridView g = sender as ASPxGridView;

        if (IsGridUngrouped)
            rowInGroupNumber = e.VisibleRowIndex + 1;
        else {
            if (isFirstDisplayedRow) {
                rowInGroupNumber = e.VisibleRowIndex - GetParentGroupIndex(e.VisibleRowIndex);
                isFirstDisplayedRow = false;
            }
            else {
                if (IsRowIsFirstGroup(e.VisibleRowIndex))
                    rowInGroupNumber = 1;
                else
                    rowInGroupNumber++;
            }
        }
        e.Value = rowInGroupNumber;
        e.DisplayText = rowInGroupNumber.ToString();
    }
    protected void grid_BeforeGetCallbackResult(object sender, EventArgs e) {
        CollectGroupIndexes();
    }

    private void CollectGroupIndexes() {
        groupIndexes.Clear();
        for (int i = 0; i < grid.VisibleRowCount; i++) {
            if (grid.IsGroupRow(i))
                groupIndexes.Add(i);
        }
    }
    private int GetParentGroupIndex(int index) {
        return groupIndexes.FindLast(delegate(int i) { return i < index; });
    }

    private bool IsRowIsFirstGroup(int index) {
        return grid.IsGroupRow(index - 1);
    }
}
See Also