Radgrid grouping

7 posts, 1 answers
  1. Ali Akbar
    Ali Akbar avatar
    22 posts
    Member since:
    Aug 2009

    Posted 04 Aug 2009 Link to this post

     Below is the code which is grouping the data based on name field, i also want one more level above the name field ex: category how do i do it?


    Thanks a million in advance.









     <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceI="SqlDataSource1" 
       GridLines="None" 
       AllowPaging="false" PageSize="25" 
       Skin="Outlook" DataSourceID="SqlDataSource1">  
     
     
     <MasterTableView DataSourceID="SqlDataSource1">  
       <GroupByExpressions> 
             <telerik:GridGroupByExpression  > 
             <SelectFields> 
              <telerik:GridGroupByField  
                FieldName="name" HeaderText=""/>  
             </SelectFields> 
               <GroupByFields> 
                  <telerik:GridGroupByField  
                     FieldName="name" /> 
                   </GroupByFields> 
             </telerik:GridGroupByExpression> 
       </GroupByExpressions> 
        </MasterTableView> 
        <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="false" AllowColumnsReorder="false">  
                    <Selecting AllowRowSelect="false"></Selecting> 
                                </ClientSettings> 
       
    </telerik:RadGrid> 
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Aug 2009 Link to this post

    Hello Ali,

    You can add another groupbyexpression as shown below:
    aspx:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceI="SqlDataSource1"  
       GridLines="None" AllowPaging="false" PageSize="25" Skin="Outlook" >    
      <MasterTableView DataSourceID="SqlDataSource1">   
        <GroupByExpressions>  
           <telerik:GridGroupByExpression>          
             <GroupByFields>  
                  <telerik:GridGroupByField FieldName="category" />  
             </GroupByFields>  
             <SelectFields>  
              <telerik:GridGroupByField FieldName="category"/>   
             </SelectFields>  
           </telerik:GridGroupByExpression>  
        </GroupByExpressions> 
        <GroupByExpressions>  
           <telerik:GridGroupByExpression>  
             <SelectFields>  
              <telerik:GridGroupByField FieldName="name" HeaderText=""/>   
             </SelectFields>  
             <GroupByFields>  
                  <telerik:GridGroupByField FieldName="name" />  
             </GroupByFields>  
           </telerik:GridGroupByExpression>  
       </GroupByExpressions>    
     </MasterTableView>  
        .... 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ali Akbar
    Ali Akbar avatar
    22 posts
    Member since:
    Aug 2009

    Posted 04 Aug 2009 Link to this post

    Thanks a lot for writing it worked.


  5. Kevin McGinnis
    Kevin McGinnis avatar
    4 posts
    Member since:
    Aug 2009

    Posted 28 Aug 2009 Link to this post

    Is it possible to add multiple GroupByExpressions programatically (C#)?

    I tried:

    GridGroupByExpression expression = GridGroupByExpression.Parse("fld1, COUNT(fld1) Total GROUP BY fld1");
    RadGrid1.MasterTableView.GroupByExpressions.Add(expression);

    GridGroupByExpression expression2 = GridGroupByExpression.Parse("fld2,, SUM(fld2) Total GROUP BY fld2");
    RadGrid1.MasterTableView.GroupByExpressions.Add(expression2);

    And it appears that only the second expression applies, resulting in a grid with only one level.  Editing the ASPX direclty, as shown in the previous post, results in two levels, at least proving that my data is valid.

    Thanks!

  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Aug 2009 Link to this post

    Hi,

    Try dynamically setting the Grouping for Grid as shown below.

    CS:
     
    GridGroupByExpression expression = new GridGroupByExpression(); 
     
    GridGroupByField gridGroupByField = new GridGroupByField(); 
    // SelectFields values (appear in header) 
    gridGroupByField = new GridGroupByField(); 
    gridGroupByField.FieldName = "EmployeeID"
    gridGroupByField.HeaderText = "Employee"
    gridGroupByField.HeaderValueSeparator = " for current group: "
    gridGroupByField.FormatString = "<strong>{0}</strong>"
    expression.SelectFields.Add( gridGroupByField ); 
     
    gridGroupByField = new GridGroupByField(); 
    gridGroupByField.FieldName = "Freight"
    gridGroupByField.HeaderText = "Total shipping cost is "
    gridGroupByField.HeaderValueSeparator = ""
    gridGroupByField.FormatString = "<strong>{0:0.00}</strong>"
    gridGroupByField.Aggregate = GridAggregateFunction.Sum; 
    expression.SelectFields.Add( gridGroupByField ); 
    //GroupByFields values (group data) 
    gridGroupByField = new GridGroupByField(); 
    gridGroupByField.FieldName = "EmployeeID"
    expression.GroupByFields.Add( gridGroupByField ); 
     
    tableViewOrders.GroupByExpressions.Add( expression ); 


    You can also refer the following help artcle for getting more details.
    Programmatic definition

    Thanks
    Princy


  7. Kiara
    Kiara avatar
    1 posts
    Member since:
    Sep 2016

    Posted 08 Sep in reply to Princy Link to this post

     

    I have written the same code but this is not working for Sum Aggregate function.In the gridgroupheaderitem the header text is not generating the sum of the values of the specified column---

    Code:
    GridGroupByExpression expression = new GridGroupByExpression(); 

     

    GridGroupByField gridGroupByField = new GridGroupByField(); 

    //GroupByFields values (group data) 
    gridGroupByField = new GridGroupByField(); 
    gridGroupByField.FieldName = "EmployeeID"; 
    expression.GroupByFields.Add( gridGroupByField ); 

     

    // SelectFields values (appear in header) 
    gridGroupByField = new GridGroupByField(); 
    gridGroupByField.FieldName = "EmployeeID"; 
    gridGroupByField.HeaderText = "Employee"; 
    gridGroupByField.HeaderValueSeparator = " for current group: "; 
    gridGroupByField.FormatString = "<strong>{0}</strong>"; 
    expression.SelectFields.Add( gridGroupByField ); 

    gridGroupByField = new GridGroupByField(); 
    gridGroupByField.FieldName = "Freight"; 
    gridGroupByField.HeaderText = "Total shipping cost is "; 
    gridGroupByField.HeaderValueSeparator = ""; 
    gridGroupByField.FormatString = "<strong>{0:0.00}</strong>"; 
    gridGroupByField.Aggregate = GridAggregateFunction.Sum; 
    expression.SelectFields.Add( gridGroupByField ); 

    tableViewOrders.GroupByExpressions.Add( expression ); 

     

    Can anyone help...??

  8. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 13 Sep Link to this post

    Hi Ali,

    Can you please share the entire page markup and related code behind so that we can revise your code locally and advise you further?

    Regards,
    Maria Ilieva
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017