I just noticed that in a grid I have been working on is displaying group aggregate totals incorrectly. This occurs any time I group more than one column together.
Here is a link displaying the problem: Grouping Problem.
Here is the relevant aspx code for the grouping:
And the code behind:
Any clues to why this might be occuring would be very helpful!
Thanks!
Here is a link displaying the problem: Grouping Problem.
Here is the relevant aspx code for the grouping:
| <telerik:RadGrid ID="CurrentCostCentersGrid" runat="server" Skin="Vista" AllowMultiRowSelection="True" |
| AllowMultiRowEdit="True" AllowFilteringByColumn="false" ShowGroupPanel="True" |
| AllowPaging="True" DataSourceID="DataSourceUnits" GridLines="Horizontal" AutoGenerateColumns="False" |
| PageSize="50" ShowFooter="true" Width="100%"> |
| <ClientSettings AllowDragToGroup="true" AllowGroupExpandCollapse="true" AllowColumnsReorder="false" |
| AllowExpandCollapse="true" AllowColumnHide="true"> |
| <Selecting AllowRowSelect="true" /> |
| <ClientEvents OnRowSelected="CostCenterSelected" OnRowDeselected="CostCenterUnselected" |
| OnRowSelecting="checkValidRowTarget" OnRowDeselecting="checkValidRowTarget" /> |
| </ClientSettings> |
| <GroupPanel Enabled="true" Text="Groups"> |
| </GroupPanel> |
| <PagerStyle Mode="NextPrevAndNumeric" NextPageText="Next" PrevPageText="Previous" /> |
| <MasterTableView ShowGroupFooter="true" ShowFooter="true" DataSourceID="DataSourceUnits" |
| DataKeyNames="CostCenterItemID" CommandItemDisplay="None" ClientDataKeyNames="CostCenterItemID"> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| <ItemStyle VerticalAlign="Top" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn Visible="False" UniqueName="ExpandColumn"> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| <ItemStyle VerticalAlign="Top" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridTemplateColumn UniqueName="StatusIcon" Groupable="false" DataField="StatusName"> |
| <ItemTemplate> |
| <asp:Image ID="StatusIcon" runat="server" ImageUrl='<%# "./images/statusicons/" + Eval("ImageName") + ".png" %>' |
| AlternateText='<%#Eval("StatusName") %>' /> |
| </ItemTemplate> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridClientSelectColumn UniqueName="ClientSideSelect"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" /> |
| </telerik:GridClientSelectColumn> |
| <telerik:GridBoundColumn Display="false" DataField="StatusID" UniqueName="StatusID" /> |
| <telerik:GridBoundColumn HeaderText="Fund" DataField="FundID" AllowFiltering="true" |
| DataType="System.Int32" SortExpression="FundID" ReadOnly="True" UniqueName="FundID"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Unit" DataField="UnitID" AllowFiltering="true" |
| DataType="System.Int32" SortExpression="UnitID" ReadOnly="True" UniqueName="UnitID"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Object" DataField="LineItemID" AllowFiltering="true" |
| DataType="System.Int32" SortExpression="LineItemID" ReadOnly="True" UniqueName="LineItemID"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Description" DataField="LineItemName" SortExpression="LineItemName" |
| UniqueName="Description" ReadOnly="true" Groupable="false"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Left" Wrap="true" Width="150px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Prev Budget" DataField="PreviousBudget" AllowFiltering="true" |
| DataType="System.Decimal" SortExpression="PreviousBudget" UniqueName="PreviousBudget" |
| DataFormatString="{0:C}" ReadOnly="True" Aggregate="Sum" FooterAggregateFormatString="{0:C}" |
| Groupable="false" Display="false"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" Width="100px" /> |
| <FooterStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Prev Actual" DataField="PreviousActual" DataType="System.Decimal" |
| SortExpression="PreviousActual" UniqueName="PreviousActual" DataFormatString="{0:C}" |
| Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}" Display="false"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" Width="100px" /> |
| <FooterStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Current Budget" DataField="CurrentBudget" DataType="System.Decimal" |
| SortExpression="CurrentBudget" UniqueName="CurrentBudget" DataFormatString="{0:C}" |
| Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" Width="100px" /> |
| <FooterStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="YTD" DataField="CurrentYTD" DataType="System.Decimal" |
| SortExpression="CurrentYTD" UniqueName="CurrentYTD" DataFormatString="{0:C}" |
| Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" Width="100px" /> |
| <FooterStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Proposed" DataField="ProposedBudget" DataType="System.Decimal" |
| SortExpression="ProposedBudget" UniqueName="ProposedBudget" Groupable="false" |
| Aggregate="Sum" FooterAggregateFormatString="{0:C}" DataFormatString="{0:C}"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" Width="100px" /> |
| <FooterStyle VerticalAlign="Top" HorizontalAlign="Right" Wrap="false" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Category" EmptyDataText="&nbsp;" HeaderText="Category" |
| SortExpression="Category" UniqueName="Category"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Left" Wrap="false" Width="115px" |
| Font-Size="10px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Group" EmptyDataText="&nbsp;" HeaderText="Group" |
| SortExpression="Group" UniqueName="Group"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Left" Wrap="false" Width="100px" |
| Font-Size="10px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn HeaderText="Modified" DataField="ModifyDate" UniqueName="Modified" |
| Groupable="false"> |
| <ItemTemplate> |
| <strong> |
| <%#Eval("ModifyBy")%></strong><br /> |
| <%#Eval("ModifyDate")%> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn HeaderText="Imported" DataField="DateLastImported" UniqueName="ImportDate" |
| Groupable="false"> |
| <ItemTemplate> |
| <img src="Images/Button-Refresh-16x16.png" alt="Imported at <%#Eval("LastImportDate") %>" /> |
| </ItemTemplate> |
| <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridButtonColumn ButtonType="ImageButton" ImageUrl="Images/graph1_16x16.gif" |
| CommandName="GraphCostCenter" Groupable="false" UniqueName="GraphCurrentYTD" |
| Text="Graph YTD Spending"> |
| <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| <DetailTables> |
| <telerik:GridTableView DataSourceID="DataSourceHistory" AutoGenerateColumns="false" |
| ShowHeader="false" GroupsDefaultExpanded="false" NoDetailRecordsText="No notes currently exist for this item" |
| Width="100%" CommandItemDisplay="Top" Frame="Void" Name="RequestHistory" DataKeyNames="HistoryID"> |
| <CommandItemTemplate> |
| <telerik:RadToolBar ID="DetailsToolbar" runat="server" Skin="Vista" Width="100%" |
| AutoPostBack="true" OnClientLoad="SetNestedToolbar"> |
| <ExpandAnimation Type="OutQuad" Duration="150" /> |
| <CollapseAnimation Type="InQuad" Duration="150" /> |
| <Items> |
| <telerik:RadToolBarButton Text="Make Request" CommandName="MakeRequest" ImageUrl="Images/request.gif"> |
| </telerik:RadToolBarButton> |
| <telerik:RadToolBarButton IsSeparator="true"> |
| </telerik:RadToolBarButton> |
| <telerik:RadToolBarButton Text="Approval" CommandName="ApproveRequest"> |
| </telerik:RadToolBarButton> |
| </Items> |
| </telerik:RadToolBar> |
| </CommandItemTemplate> |
| <ParentTableRelation> |
| <telerik:GridRelationFields MasterKeyField="CostCenterItemID" DetailKeyField="ItemID" /> |
| </ParentTableRelation> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| <ItemStyle VerticalAlign="Top" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| <ItemStyle VerticalAlign="Top" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridTemplateColumn UniqueName="History"> |
| <ItemTemplate> |
| <strong> |
| <%#Eval("CreateDate","{0:d}") %> <%#Eval("CreateDate","{0:t}") %> - <%#Eval("UserName")%>:</strong> <br /> |
| <strong>Status:</strong> |
| <asp:Image ID="OldStatusIcon" runat="server" /><img src="Images/right.gif" alt="to" /><asp:Image |
| ID="NewStatusIcon" runat="server" /> |
| <p style="margin-top: 3px; margin-bottom: 2px; margin-left: 15px;"> |
| <%#Eval("NoteText")%></p> |
| <asp:Panel ID="RequestPanel" runat="server"> |
| <strong style="color: Red">Amount Requested:</strong> |
| <%#Eval("RequestedBudget", "{0:C}")%></asp:Panel> |
| <hr /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </telerik:GridTableView> |
| </DetailTables> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| </MasterTableView> |
| </telerik:RadGrid> |
And the code behind:
| Protected Sub InjectImages(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles CurrentCostCentersGrid.ItemDataBound |
| If e.Item.OwnerTableView.DataSourceID = "DataSourceHistory" Then |
| If e.Item.ItemType = Telerik.Web.UI.GridItemType.AlternatingItem Or e.Item.ItemType = Telerik.Web.UI.GridItemType.Item Then |
| Dim item As Telerik.Web.UI.GridDataItem = e.Item |
| Dim OldIcon As Image = item("History").FindControl("OldStatusIcon") |
| Dim NewIcon As Image = item("History").FindControl("NewStatusIcon") |
| Dim data As Southwestern.BudgetPortal.Data.CostCenter_GetNotesResult = item.DataItem |
| If data.IsManagementNote = True Then |
| Dim RequestPanel As Panel = item("History").FindControl("RequestPanel") |
| RequestPanel.Visible = False |
| End If |
| Dim OldStatus As Southwestern.BudgetPortal.Data.CostCenterStatus = (From S In Repository.CostCenterStatus Where S.StatusID = data.OldStatusID).Single() |
| Dim NewStatus As Southwestern.BudgetPortal.Data.CostCenterStatus = (From S In Repository.CostCenterStatus Where S.StatusID = data.StatusID).Single() |
| OldIcon.ImageUrl = "images/statusicons/" & OldStatus.ImageName & ".png" |
| OldIcon.AlternateText = "Old Status: " & OldStatus.StatusName |
| NewIcon.ImageUrl = "images/statusicons/" & NewStatus.ImageName & ".png" |
| NewIcon.AlternateText = "New Status: " & NewStatus.StatusName |
| End If |
| End If |
| End Sub |
| Protected Sub AllowCheckbox(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles CurrentCostCentersGrid.ItemDataBound |
| If e.Item.OwnerTableView.DataSourceID <> "DataSourceHistory" Then |
| If e.Item.ItemType = Telerik.Web.UI.GridItemType.AlternatingItem Or e.Item.ItemType = Telerik.Web.UI.GridItemType.Item Then |
| Dim user As Southwestern.BudgetPortal.Data.SystemUser = WebHelper.GetSystemUser() |
| If user.PortalAdministrator = False And user.SiteAdministrator = False Then |
| ' Check permissions on the item. Checkboxes should only be enabled for manage rights. |
| Dim item As Telerik.Web.UI.GridDataItem = e.Item |
| Dim data As Southwestern.BudgetPortal.Data.CostCenter_GetAvailableUnitsResult = item.DataItem |
| Dim unitRights As Southwestern.BudgetPortal.Data.UnitPermission = (From UP In Repository.UnitPermissions _ |
| Where UP.SamAccountName = user.SamAccountName _ |
| And UP.UnitID = data.UnitID).Single() |
| Dim checkBox As CheckBox = CType(item("ClientSideSelect").Controls(0), CheckBox) |
| If unitRights IsNot Nothing AndAlso unitRights.UnitManager = True Then |
| checkBox.Enabled = True |
| Else |
| checkBox.Enabled = False |
| End If |
| End If |
| ElseIf e.Item.ItemType = Telerik.Web.UI.GridItemType.Header Then |
| ' Hide the checkbox in the header if this user is not a portal administrator |
| Dim user As Southwestern.BudgetPortal.Data.SystemUser = WebHelper.GetSystemUser() |
| If user.PortalAdministrator = False And user.SiteAdministrator = False Then |
| Dim item As Telerik.Web.UI.GridHeaderItem = e.Item |
| Dim checkBox As CheckBox = CType(item("ClientSideSelect").Controls(0), CheckBox) |
| checkBox.Visible = False |
| End If |
| End If |
| End If |
| End Sub |
| Protected Sub GreyOutReviewOnlyItems(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles CurrentCostCentersGrid.ItemDataBound |
| If e.Item.OwnerTableView.DataSourceID <> "DataSourceHistory" Then |
| If e.Item.ItemType = Telerik.Web.UI.GridItemType.AlternatingItem Or e.Item.ItemType = Telerik.Web.UI.GridItemType.Item Then |
| Dim data As Southwestern.BudgetPortal.Data.CostCenter_GetAvailableUnitsResult = e.Item.DataItem |
| If data.ReviewOnly = True Then |
| For Each Cell As TableCell In e.Item.Cells |
| Cell.ForeColor = Drawing.Color.Gray |
| Cell.Font.Bold = True |
| Cell.Font.Italic = True |
| Cell.BackColor = Drawing.Color.FromArgb(200, 200, 200) |
| Cell.BorderColor = Drawing.Color.FromArgb(200, 200, 200) |
| Next |
| End If |
| End If |
| End If |
| End Sub |
| Protected Sub CurrentCostCentersGrid_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles CurrentCostCentersGrid.DetailTableDataBind |
| Dim UnitID As Integer = e.DetailTableView.ParentItem.Item("UnitID").Text |
| Dim Manager As Boolean = False |
| Dim Write As Boolean = False |
| Dim User As Southwestern.BudgetPortal.Data.SystemUser = WebHelper.GetSystemUser() |
| If User.PortalAdministrator = True Or User.SiteAdministrator = True Then |
| Manager = True |
| Write = True |
| Else |
| Try |
| Manager = (From P As Southwestern.BudgetPortal.Data.UnitPermission In WebHelper.GetSystemUser().UnitPermissions Where P.UnitID = UnitID Select P.UnitManager).Single() |
| Write = (From P As Southwestern.BudgetPortal.Data.UnitPermission In WebHelper.GetSystemUser().UnitPermissions Where P.UnitID = UnitID Select P.Editor).Single() |
| Catch ex As Exception |
| End Try |
| End If |
| If User.PortalAdministrator = False And User.SiteAdministrator = False Then |
| Dim StatusIDText As String = e.DetailTableView.ParentItem.Item("StatusID").Text |
| Dim StatusID As Integer = 0 |
| Dim LockItem As Boolean = True |
| If Integer.TryParse(StatusIDText, StatusID) Then |
| ' get the status item |
| Dim StatusEntry = (From Status In Repository.CostCenterStatus Where Status.StatusID = StatusID).Single() |
| If Write = True And Manager = False And StatusEntry.LocksCostCenter = True Then |
| ' first condition, non-unit manager and cost center status indicates locked |
| LockItem = True |
| ElseIf Manager = True Then |
| ' second condition, unit manager |
| If StatusEntry.UnitManagerSet = False And StatusEntry.PortalAdminSet = True And StatusEntry.LocksCostCenter = True Then |
| ' portal administrator has locked it |
| LockItem = True |
| Else |
| LockItem = False |
| End If |
| ElseIf Write = False And Manager = False Then |
| ' The user has read only access |
| LockItem = True |
| Else |
| LockItem = False |
| End If |
| End If |
| If LockItem = True Then |
| e.DetailTableView.CommandItemDisplay = Telerik.Web.UI.GridCommandItemDisplay.None |
| Exit Sub |
| End If |
| End If |
| ' Currently hiding buttons client side |
| Dim Script As String = "canApprove={0};canEdit={1};Sys.Application.add_load(SetApprovalVisibility);Sys.Application.add_load(SetNestedToolbarVisibility);" |
| If Manager = True Then |
| Script = String.Format(Script, "true", "true") |
| ElseIf Write = True Then |
| Script = String.Format(Script, "false", "true") |
| Else |
| Script = String.Format(Script, "false", "false") |
| End If |
| ScriptManager.RegisterStartupScript(Me, source.GetType(), "SetUnitToolbar", Script, True) |
| End Sub |
| Protected Sub CurrentCostCentersGrid_GroupsChanging(ByVal source As Object, ByVal e As Telerik.Web.UI.GridGroupsChangingEventArgs) Handles CurrentCostCentersGrid.GroupsChanging |
| ' Used to show/hide group by columns |
| Dim GroupByFieldName As String = e.Expression.GroupByFields(0).FieldName ' The unique name of the column |
| Dim GroupByColumn As Telerik.Web.UI.GridColumn = CurrentCostCentersGrid.MasterTableView.GetColumnSafe(GroupByFieldName) ' The actual column |
| If e.Action = Telerik.Web.UI.GridGroupsChangingAction.Group Then |
| ' We are grouping, so hide the column in the grid. |
| GroupByColumn.Visible = False |
| ElseIf e.Action = Telerik.Web.UI.GridGroupsChangingAction.Ungroup Then |
| ' We are ungrouping, so show the column again. |
| GroupByColumn.Visible = True |
| End If |
| End Sub |
Any clues to why this might be occuring would be very helpful!
Thanks!