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

Dynamic RadGrid Grouping problem

2 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali Akbar
Top achievements
Rank 1
Ali Akbar asked on 04 Aug 2009, 03:49 PM

Below is the code i have created and wanted to group it based on "name" column. But i am not able to group it and normal values are being rendered in the grid...

 RadGrid radGrid1 = new RadGrid();  
        radGrid1.ID = "radgrid1";  
          
 
 
          
        radGrid1.DataSourceID = "SqlDataSource1";  
        radGrid1.GridLines = GridLines.None;  
 
        GridTableView gridTableView = new GridTableView(radGrid1);  
        gridTableView.GroupsDefaultExpanded = true;  
        gridTableView.DataSourceID = "SqlDataSource1";  
 
        GridGroupByExpression expression = new GridGroupByExpression();  
        GridGroupByField gridGroupByField = new GridGroupByField();  
        gridGroupByField = new GridGroupByField();  
        gridGroupByField.FieldName = "name";  
        gridGroupByField.HeaderText = "Name";  
        expression.SelectFields.Add(gridGroupByField);  
 
        gridGroupByField = new GridGroupByField();  
        gridGroupByField.FieldName = "name";  
        gridGroupByField.HeaderText = "Name";  
        expression.GroupByFields.Add(gridGroupByField);  
 
        gridTableView.GroupByExpressions.Add(expression);  
        this.Controls.Add(radGrid1); 

Thanks a million in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 05 Aug 2009, 07:24 AM
Hi Ali,

In the above given code I can see that you are adding the GridGroupByExpression to the GridTableView. Instead try adding it directly to the MasterTableView instance of the RadGrid. Here is the modified code. Give a try with the following approach and see whether it helps.

CS:
 
 
 protected void Page_Init(object sender, EventArgs e) 
    { 
        RadGrid radGrid1 = new RadGrid(); 
        radGrid1.ID = "radGrid1"
 
        radGrid1.DataSourceID = "SqlDataSource1"
        radGrid1.GridLines = GridLines.None; 
 
        radGrid1.MasterTableView.GroupsDefaultExpanded = false
 
        GridGroupByExpression expression = new GridGroupByExpression(); 
        GridGroupByField gridGroupByField = new GridGroupByField(); 
        gridGroupByField = new GridGroupByField(); 
        gridGroupByField.FieldName = "name"
        gridGroupByField.HeaderText = "Name"
        expression.SelectFields.Add(gridGroupByField); 
 
        gridGroupByField = new GridGroupByField(); 
        gridGroupByField.FieldName = "name"
        gridGroupByField.HeaderText = "Name"
        expression.GroupByFields.Add(gridGroupByField); 
 
        radGrid1.MasterTableView.GroupByExpressions.Add(expression); 
        this.PlaceHolder1.Controls.Add(radGrid1);  
        
 
    } 


Regards
Shinu
0
Ali Akbar
Top achievements
Rank 1
answered on 05 Aug 2009, 09:21 AM
Awesome dude! thanks a million shinu you are really a master.



Tags
Grid
Asked by
Ali Akbar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Ali Akbar
Top achievements
Rank 1
Share this question
or