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> |
6 Answers, 1 is accepted
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.
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!
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
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...??
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