简体   繁体   中英

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

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM