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

Need Grouping Help!

2 Answers 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sid
Top achievements
Rank 1
Sid asked on 27 May 2010, 10:05 PM
If you go to http://www.telerik.com/help/aspnet-ajax/grdbasicgrouping.html, it shows a graphic of a RadGrid with Supplier and Category grouping (first graphic).  I need to do a similar two level grouping:

Top Level
   Second Level
      Data
   Second Level
      Data
Top Level
   Second Level
      Data
  ...

How do you do this programmatically (in C#)?  I've gotten the first level to work, but can't get the second.  See code snippet below.

      GridGroupByExpression expression = new GridGroupByExpression();
      GridGroupByField      gridGroupByField;

      MyGrid.DataSource = ds; // dataset 
 
      gridGroupByField = new GridGroupByField(); 
      gridGroupByField.FieldName = "TopLevel"
      gridGroupByField.HeaderText = " "
      gridGroupByField.HeaderValueSeparator = ""
      gridGroupByField.FormatString = "<strong>{0}</strong>"
      expression.SelectFields.Add( gridGroupByField ); 
 
      gridGroupByField = new GridGroupByField(); 
      gridGroupByField.FieldName = "TopLevel"
      expression.GroupByFields.Add( gridGroupByField ); 
 
      MyGrid.MasterTableView.GroupByExpressions.Add(expression); 
       
      MyGrid.DataBind(); 

Thanks,
Gary

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 May 2010, 12:19 PM
Hello Gary,

You need to use seperate GridGroupByExpression for each level of grouping. Check out the following code snippet.

C#:
 
            GridGroupByExpression expression = 
new GridGroupByExpression(); 
            GridGroupByField gridGroupByField; 
 
            gridGroupByField = new GridGroupByField(); 
            gridGroupByField.FieldName = "EmployeeID"
            gridGroupByField.HeaderText = "id "
            gridGroupByField.HeaderValueSeparator = ""
            gridGroupByField.FormatString = "<strong>{0}</strong>"
            expression.SelectFields.Add(gridGroupByField); 
            expression.GroupByFields.Add(gridGroupByField); 
            RadGrid1.MasterTableView.GroupByExpressions.Add(expression); 
 
            GridGroupByExpression expression1 = new GridGroupByExpression(); 
            GridGroupByField gridGroupByField1; 
            gridGroupByField1 = new GridGroupByField(); 
            gridGroupByField1.FieldName = "user_role"
            gridGroupByField1.HeaderText = "user_role "
            expression1.SelectFields.Add(gridGroupByField1); 
            expression1.GroupByFields.Add(gridGroupByField1); 
            RadGrid1.MasterTableView.GroupByExpressions.Add(expression1);  
 

Regards,
Shinu.
0
Sid
Top achievements
Rank 1
answered on 01 Jun 2010, 10:05 PM
THANKS!!!
That did the trick.  I appreciate your help.

Regards,
Gary
Tags
Grid
Asked by
Sid
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sid
Top achievements
Rank 1
Share this question
or