Search code examples
c#group-bydevexpressaspxgridview

DevExpress: ASPxGridView GroupBy() won't work


My goal is to group the data at runtime inside a grdView which added to a panel also at runtime

grdView.DataSource = tbl;
grdView.DataBind();
grdView.Settings.ShowGroupPanel = true;
grdView.BeginUpdate();
grdView.GroupBy((DevExpress.Web.ASPxGridView.GridViewDataColumn) grdView.Columns["ClmnName"]);//or an index (0) for example
grdView.EndUpdate();

any suggestions?

EDIT: Current Code

//GRID
pnlGrids.Controls.Add(grdView);
grdView.DataSource = tbl;//Datasource
foreach (GridViewDataTextColumn clmn in grdView.Columns)//HTML
     clmn.PropertiesTextEdit.EncodeHtml = false;
if (key.GroupingDataMembers.Any())//Group panel
     grdView.Settings.ShowGroupPanel = true;
grdView.Images.ImageFolder = "~/App_Themes/Aqua/GridView/";//Style
grdView.Styles.CssFilePath = "~/App_Themes/Aqua/GridView/styles.css";
grdView.Styles.CssPostfix = "Aqua";
grdView.DataBind();//Bind
if (key.GroupingDataMembers.Any())//Grouping
     (grdView.Columns[key.GroupingDataMembers.First().DataMember.DisplayName] as DevExpress.Web.ASPxGridView.GridViewDataColumn).GroupBy();
grdView.ExpandAll();//Expand all

Solution

  • The following code works fine here:

    protected void Page_Load(object sender, EventArgs e) {
        ASPxGridView grid = new ASPxGridView();
        grid.ID = "grid";
        pnl.Controls.Add(grid);
        DataTable t = new DataTable();
        t.Columns.Add("Id");
        t.Columns.Add("Data");
        for(int i = 0; i < 100; i++) {
            t.Rows.Add(new object[] { i, "row " + i.ToString() });
        }
        grid.DataSource = t;
        grid.Settings.ShowGroupPanel = true;
        grid.DataBind();
    
        (grid.Columns["Data"] as GridViewDataColumn).GroupBy();
    }