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

Problems with GridGroupByExpression Count Aggregate

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raul Fajardo
Top achievements
Rank 1
Raul Fajardo asked on 28 Nov 2012, 04:20 AM
Hi
I am having troubles with the Count Aggregate. 
I have a radgrid with several levels. You can see it on the picture 


The problems is that for the first level. I have right the information.

First Level Company BATCA
 Departamento FINANZAS; Empleados: 218; Costo $14,110.00
 Carnet CONTRATISTA; Empleado_Carnets: 19; Costo $1,235.00
 Carnet HORAS EXTRAS; Empleado_Carnets: 20; Costo $1,270.00
  Carnet PERMANENTE; Empleado_Carnets: 20; Costo $1,300.00 (... group continued from the previous page. Showing     163 of 20 items. Group continues on the next page.) This information is correct, but still I don't understand why it shows me 20 in Empleados_Carnets instead of 163
 Carnet PRACTICANTE; Empleado_Carnets: 16; Costo $1,040.00

Second Level Company TAHSA

This information is completely wrong. This is the same of the first level Company BATCA
 Departamento FINANZAS; Empleados: 218; Costo $14,110.00
 Carnet PERMANENTE; Empleado_Carnets: 163; Costo $10,565.00
 Carnet PRACTICANTE; Empleado_Carnets: 16; Costo $1,040.00
 Carnet VISITA; Empleado_Carnets: 15; Costo $975.00
 

The aspx code is the following

<telerik:RadScriptManager runat="server" ID="RadScriptManager1"></telerik:RadScriptManager>
       <form id="Form1" method="post" runat="server">
           <TABLE id="Table4" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 40px; BORDER-COLLAPSE: collapse"
               height="99%" cellSpacing="1" cellPadding="1" width="95%" border="0">
               <TR>
                   <TD vAlign="top" align="left">
                       <TABLE id="Table1" style="BORDER-COLLAPSE: collapse" cellSpacing="1" cellPadding="1" width="300"
                           border="1">
                           <TR>
                               <TD align="center" background="..\imagenes\titulos2.jpg"><asp:label id="Label3" runat="server" Height="100%" Width="474px" CssClass="text">Tipo de Carnet</asp:label></TD>
                           </TR>
                           <TR>
                               <TD>
                                   <TABLE id="Table2" height="100%" cellSpacing="1" cellPadding="1" width="100%" border="0">
                                       <TR>
                                           <TD noWrap><asp:label id="Label4" runat="server" CssClass="label1">Fecha Inicio</asp:label></TD>
                                           <TD style="WIDTH: 226px">
                                               <cc1:livetextbox id="fechain" runat="server" CssClass="flat">10/09/2006</cc1:livetextbox><IMG id="Img2" onclick="javascript:fPopCalendar(fechain,fechain,1,4,'/')" alt="" src="..\imagenes\calendar.png"></TD>
                                           <TD noWrap><asp:label id="Label1" runat="server" CssClass="label1">Fecha Fin</asp:label></CC1:LIVELABEL></TD>
                                           <TD noWrap>
                                               <cc1:livetextbox id="fechafin" runat="server" CssClass="flat">10/09/2006</cc1:livetextbox><IMG id="Img1" onclick="javascript:fPopCalendar(fechafin,fechafin,1,4,'/')" alt="" src="..\imagenes\calendar.png"></TD>
                                       </TR>
                                   </TABLE>
                               </TD>
                           </TR>
                           <TR>
                               <TD><asp:button id="Button2" runat="server" CssClass="gridupdate" ToolTip="Aceptar"
                                       onclick="Button2_Click1"></asp:button>
                                   <asp:button id="Button1" runat="server" CssClass="excel" ToolTip="Exportar a Excel"></asp:button></TD>
                           </TR>
                       </TABLE>
                       <telerik:radgrid id="RadGrid1" runat="server" ShowGroupPanel="True" AllowSorting="True" CssClass="Windows7" Skin="Windows7" >
                           <PagerStyle CssClass="GridPager_Default" ></PagerStyle>
                           <AlternatingItemStyle CssClass="GridAltRow_Default"></AlternatingItemStyle>
                           <GroupHeaderItemStyle CssClass="GroupHeader_Default"></GroupHeaderItemStyle>
                           <FilterMenu NotSelectedImageUrl="~/RadControls/Grid/Skins/Default/NotSelectedMenu.gif" HoverBackColor="LightSteelBlue"
                               HoverBorderColor="Navy" SelectColumnBackColor="Control" SelectedImageUrl="~/RadControls/Grid/Skins/Default/SelectedMenu.gif"
                               TextColumnBackColor="Window"></FilterMenu>
                           <MasterTableView CssClass="MasterTable_Default">
                               <RowIndicatorColumn UniqueName="RowIndicator" Visible="False">
                                   <HeaderStyle Width="20px" CssClass="ResizeHeader_Default"></HeaderStyle>
                                   <ItemStyle CssClass="ResizeItem_Default"></ItemStyle>
                               </RowIndicatorColumn>
                               <EditFormSettings>
                                   <EditColumn UniqueName="EditCommandColumn"></EditColumn>
                               </EditFormSettings>
                               <ExpandCollapseColumn ButtonType="ImageButton" UniqueName="ExpandColumn" Visible="False">
                                   <HeaderStyle Width="19px"></HeaderStyle>
                               </ExpandCollapseColumn>
                           </MasterTableView>
                           <HeaderStyle CssClass="GridHeader_Default"></HeaderStyle>
                           <SelectedItemStyle CssClass="SelectedRow_Default"></SelectedItemStyle>
                           <ActiveItemStyle CssClass="ActiveRow_Default"></ActiveItemStyle>
                           <ItemStyle CssClass="GridRow_Default"></ItemStyle>
                           <FooterStyle CssClass="GridFooter_Default"></FooterStyle>
                           <ClientSettings AllowExpandCollapse="True" AllowRowHide="True" AllowDragToGroup="True" AllowGroupExpandCollapse="True">
                               <Resizing AllowColumnResize="True"></Resizing>
                           </ClientSettings>
                           <GroupPanel Visible="True">
                               <PanelStyle CssClass="GroupPanel_Default"></PanelStyle>
                               <PanelItemsStyle CssClass="GroupPanelItems_Default"></PanelItemsStyle>
                           </GroupPanel>
                       </telerik:radgrid></TD>
               </TR>
               <TR>
                   <TD vAlign="bottom" align="right"><cc1:liveimage id="LiveImage1" runat="server" Height="218px" Width="305px" ImageUrl="..\imagenes\fondo2.jpg"></cc1:liveimage></TD>
               </TR>
           </TABLE>
       </form>



The c# code is the following


private void Page_Load(object sender, System.EventArgs e)
        {
            if(!IsPostBack)
            {
                this.fechain.Text="01"+DateTime.Now.ToString("/MMM/yyyy");
                this.fechafin.Text=DateTime.Now.ToString("dd/MMM/yyyy");
       
 
                GridGroupByExpression expression = new GridGroupByExpression();
 
                GridGroupByField gridGroupByField = new GridGroupByField();
             
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "EMPRESA";
                gridGroupByField.HeaderText = "Empresa";
                gridGroupByField.HeaderValueSeparator = " ";
                gridGroupByField.FormatString = "<strong>{0}</strong>";
                expression.SelectFields.Add( gridGroupByField );
                 
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "CODIGO";
                gridGroupByField.HeaderText = "Empleados";
                gridGroupByField.Aggregate = GridAggregateFunction.Count;
                expression.SelectFields.Add( gridGroupByField );
 
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "Total";
                gridGroupByField.HeaderText = "Costo ";
                gridGroupByField.HeaderValueSeparator = "";
                gridGroupByField.FormatString ="{0:C}";
                gridGroupByField.Aggregate = GridAggregateFunction.Sum;
                expression.SelectFields.Add( gridGroupByField );
 
                //Add a filed for group-by (after the "Group By" clause)
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "EMPRESA";
                expression.GroupByFields.Add( gridGroupByField );
 
                this.RadGrid1.MasterTableView.GroupByExpressions.Add( expression );
                 
 
                GridGroupByExpression expression1 = new GridGroupByExpression();
 
                 
                GridGroupByField gridGroupByField1 = new GridGroupByField();
 
                gridGroupByField1 = new GridGroupByField();
                gridGroupByField1.FieldName = "DEPARTAMENTO";
                gridGroupByField1.HeaderText = "Departamento";
                gridGroupByField1.HeaderValueSeparator = " ";
                gridGroupByField1.FormatString = "<strong>{0}</strong>";
                expression1.SelectFields.Add( gridGroupByField1 );
                 
                gridGroupByField1 = new GridGroupByField();
                gridGroupByField1.FieldName = "CODIGO";
                gridGroupByField1.HeaderText = "Empleados";
                gridGroupByField1.Aggregate = GridAggregateFunction.Count;
                expression1.SelectFields.Add( gridGroupByField1 );
 
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "Total";
                gridGroupByField.HeaderText = "Costo ";
                gridGroupByField.HeaderValueSeparator = "";
                gridGroupByField.FormatString ="{0:C}";
                gridGroupByField.Aggregate = GridAggregateFunction.Sum;
                expression1.SelectFields.Add( gridGroupByField );
 
                //Add a filed for group-by (after the "Group By" clause)
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "DEPARTAMENTO";
                expression1.GroupByFields.Add( gridGroupByField );
 
                this.RadGrid1.MasterTableView.GroupByExpressions.Add( expression1 );
               
 
                GridGroupByExpression expression2 = new GridGroupByExpression();
 
                 
                GridGroupByField gridGroupByField2 = new GridGroupByField();
 
                gridGroupByField2 = new GridGroupByField();
                gridGroupByField2.FieldName = "CARNET";
                gridGroupByField2.HeaderText = "Carnet";
                gridGroupByField2.HeaderValueSeparator = " ";
                gridGroupByField2.FormatString = "<strong>{0}</strong>";
                expression2.SelectFields.Add( gridGroupByField2 );
                 
                gridGroupByField2 = new GridGroupByField();
                gridGroupByField2.FieldName = "CODIGO";
                gridGroupByField2.HeaderText = "Empleado_Carnets";
                gridGroupByField2.Aggregate = GridAggregateFunction.Count;
                expression2.SelectFields.Add( gridGroupByField2 );
 
 
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "Total";
                gridGroupByField.HeaderText = "Costo ";
                gridGroupByField.HeaderValueSeparator = "";
                gridGroupByField.FormatString ="{0:C}";
                gridGroupByField.Aggregate = GridAggregateFunction.Sum;
                expression2.SelectFields.Add( gridGroupByField );
 
                //Add a filed for group-by (after the "Group By" clause)
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "CARNET";
                expression2.GroupByFields.Add( gridGroupByField );
 
                this.RadGrid1.MasterTableView.GroupByExpressions.Add( expression2 );
                 
               
 
                GridGroupByExpression expression3 = new GridGroupByExpression();
 
                 
                GridGroupByField gridGroupByField3 = new GridGroupByField();
 
                gridGroupByField3 = new GridGroupByField();
                gridGroupByField3.FieldName = "JORNADA";
                gridGroupByField3.HeaderText = "Jornada";
                gridGroupByField3.HeaderValueSeparator = " ";
                gridGroupByField3.FormatString = "<strong>{0}</strong>";
                expression3.SelectFields.Add( gridGroupByField3 );
                 
                gridGroupByField3 = new GridGroupByField();
                gridGroupByField3.FieldName = "CODIGO";
                gridGroupByField3.HeaderText = "Empleados_Tipo";
                gridGroupByField3.Aggregate = GridAggregateFunction.Count;
                expression3.SelectFields.Add( gridGroupByField3 );
 
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "Total";
                gridGroupByField.HeaderText = "Costo ";
                gridGroupByField.HeaderValueSeparator = "";
                gridGroupByField.FormatString ="{0:C}";
                gridGroupByField.Aggregate = GridAggregateFunction.Sum;
                expression3.SelectFields.Add( gridGroupByField );
 
                //Add a filed for group-by (after the "Group By" clause)
                gridGroupByField = new GridGroupByField();
                gridGroupByField.FieldName = "JORNADA";
                gridGroupByField.SortOrder=Telerik.Web.UI.GridSortOrder.Ascending;
  
                expression3.GroupByFields.Add( gridGroupByField );
                   
 
 
                this.RadGrid1.MasterTableView.GroupByExpressions.Add( expression3 );
                this.RadGrid1.MasterTableView.GroupsDefaultExpanded=false;
 
  
 
 
            }
        }


Thanks for your help.

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 03 Dec 2012, 06:31 AM
Hi,

How the Grid is bound, using NeedDataSource event, declarative datasource like SqlDataSource, or by calling DataBind() method?

Additionally, you could try to set the EnableLinqGrouping property of RadGrid's MasterTableView to false and then check whether the issue still replicates.

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Raul Fajardo
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or