This is a migrated thread and some comments may be shown as answers.

Progromatically change grouping

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ronen Divon
Top achievements
Rank 1
Ronen Divon asked on 05 Mar 2009, 03:37 PM
I have created a radgrid programatically and want to be able to change the groupbyfield programatically, but it seems as though the viewstate keeps track of that and I can't override it. Has anyone done this before? If so can you provide source code.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Mar 2009, 06:55 AM
Hi,

Try the following code snippet to set Grouping for a dynamically created Grid.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        RadGrid Grid = (RadGrid)PlaceHolder1.FindControl("RadGrid1"); 
        if (Grid!=null
        { 
            Grid.MasterTableView.GroupByExpressions.Clear();
            GridGroupByExpression exp = new GridGroupByExpression(); 
            GridGroupByField GroupByField=new GridGroupByField(); 
            GroupByField.FieldName="SupplierID"
            GroupByField.FieldAlias="SupplierID"
 
            exp.GroupByFields.Add(GroupByField); 
            exp.SelectFields.Add(GroupByField); 
            Grid.MasterTableView.GroupByExpressions.Add(exp); 
        } 
    } 


Thanks
Shinu
Tags
Grid
Asked by
Ronen Divon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or