How to add total in footer in case of editable grid with paging and DataSourceID?
Now I'm adding total in ItemDataBound by summarize the values and update GridFooterItem
but in this case because of the paging, it doesn't summarize them all, just
the rows in current page. i need to summarize all and update the total
when the grid content is updated.
what is the correct approach in this case?
aspx:
-----
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadSplitter ID="mainSplitter" runat="server" Height="100%" Width="100%"
Orientation="Horizontal" VisibleDuringInit="false" BorderSize="0" PanesBorderSize="0">
<telerik:RadPane ID="paneTitle" runat="server" Height="50px">
<h1>Production Groups</h1>
</telerik:RadPane>
<telerik:RadPane ID="paneGrid" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="ObjectDataSource1"
GridLines="None" Width="1200px" Height="95%"
AllowAutomaticDeletes="True"
AllowAutomaticInserts="True"
AllowAutomaticUpdates="True"
OnItemDataBound="RadGrid1_ItemDataBound"
OnDataBound="RadGrid1_DataBound"
>
<ClientSettings EnableRowHoverStyle="true">
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView DataKeyNames="GroupID" DataSourceID="ObjectDataSource1" CommandItemDisplay="Top" EditMode="PopUp" ShowFooter="true">
<CommandItemSettings ExportToPdfText="Export to Pdf" AddNewRecordText="Add New Production Group"></CommandItemSettings>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn HeaderText="Edit" ButtonType="ImageButton">
<ItemStyle HorizontalAlign="Center" Width="50px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="Delete this group?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" HeaderText="Delete"
CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" Width="50px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="GroupID" HeaderText="ID" ReadOnly="true"
SortExpression="GroupID" UniqueName="GroupID" DataType="System.Int32">
<ItemStyle HorizontalAlign="Center" Width="50px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="GroupName" HeaderText="Group Name"
SortExpression="GroupName" UniqueName="GroupName">
<ItemStyle Width="250px" />
<HeaderStyle Width="250px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SortOrder" HeaderText="Sort Order"
SortExpression="SortOrder" UniqueName="SortOrder">
<ItemStyle HorizontalAlign="Center" Width="80px" />
<HeaderStyle HorizontalAlign="Center" Width="80px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ProductionCost" HeaderText="Production Cost"
SortExpression="ProductionCost" UniqueName="ProductionCost" DataFormatString="{0:c2}">
<ItemStyle HorizontalAlign="Center" Width="80px" />
<HeaderStyle HorizontalAlign="Center" Width="80px" />
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings CaptionDataField="GroupName"
CaptionFormatString="Edit Production Group: {0}"
InsertCaption="New Production Group"
EditFormType="Template" >
<EditColumn ButtonType="ImageButton">
</EditColumn>
<PopUpSettings Modal="true" />
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="270" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Group Name:
</td>
<td>
<telerik:RadTextBox ID="TextBox10" Text='<%# Bind("GroupName") %>' runat="server">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
Sort Order:
</td>
<td>
<telerik:RadTextBox ID="TextBox11" Text='<%# Bind("SortOrder") %>' MaxLength="2" runat="server">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
Production Cost:
</td>
<td>
<telerik:RadNumericTextBox ID="txtProductionCost" runat="server" Width="100px" Type="Currency" Text='<%# Bind("ProductionCost") %>'>
<NumberFormat DecimalDigits="2" />
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="left" colspan="2">
<asp:Button ID="Button1"
runat="server" class="rgUpdate" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="Button2" class="rgCancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadPane>
</telerik:RadSplitter>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="DeleteProductionGroup" InsertMethod="InsertProductionGroup"
SelectMethod="GetAllProductionGroups" TypeName="comp.BL.ProductionController"
UpdateMethod="UpdateProductionGroup">
<DeleteParameters>
<asp:Parameter Name="GroupID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="GroupName" Type="String" />
<asp:Parameter Name="sortOrder" Type="Int32" />
<asp:Parameter Name="ProductionCost" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="GroupID" Type="Int32" />
<asp:Parameter Name="GroupName" Type="String" />
<asp:Parameter Name="sortOrder" Type="Int32" />
<asp:Parameter Name="ProductionCost" Type="Decimal" />
</UpdateParameters>
</asp:ObjectDataSource>
aspx.cs
-------
double total_ProductionCost = 0;
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridFooterItem)
{
GridFooterItem footerItem = e.Item as GridFooterItem;
footerItem["ProductionCost"].Text = "" + String.Format("{0:C2}", total_ProductionCost);
}
if (e.Item.ItemType != GridItemType.Item && e.Item.ItemType != GridItemType.AlternatingItem) return;
tblProductionGroup item = (tblProductionGroup)e.Item.DataItem;
if (item.ProductionCost.HasValue)
{
double ProductionCost = (double)item.ProductionCost;
total_ProductionCost += ProductionCost;
}
var source = RadGrid1.DataSource;
}
Now I'm adding total in ItemDataBound by summarize the values and update GridFooterItem
but in this case because of the paging, it doesn't summarize them all, just
the rows in current page. i need to summarize all and update the total
when the grid content is updated.
what is the correct approach in this case?
aspx:
-----
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadSplitter ID="mainSplitter" runat="server" Height="100%" Width="100%"
Orientation="Horizontal" VisibleDuringInit="false" BorderSize="0" PanesBorderSize="0">
<telerik:RadPane ID="paneTitle" runat="server" Height="50px">
<h1>Production Groups</h1>
</telerik:RadPane>
<telerik:RadPane ID="paneGrid" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="ObjectDataSource1"
GridLines="None" Width="1200px" Height="95%"
AllowAutomaticDeletes="True"
AllowAutomaticInserts="True"
AllowAutomaticUpdates="True"
OnItemDataBound="RadGrid1_ItemDataBound"
OnDataBound="RadGrid1_DataBound"
>
<ClientSettings EnableRowHoverStyle="true">
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView DataKeyNames="GroupID" DataSourceID="ObjectDataSource1" CommandItemDisplay="Top" EditMode="PopUp" ShowFooter="true">
<CommandItemSettings ExportToPdfText="Export to Pdf" AddNewRecordText="Add New Production Group"></CommandItemSettings>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn HeaderText="Edit" ButtonType="ImageButton">
<ItemStyle HorizontalAlign="Center" Width="50px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="Delete this group?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" HeaderText="Delete"
CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" Width="50px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="GroupID" HeaderText="ID" ReadOnly="true"
SortExpression="GroupID" UniqueName="GroupID" DataType="System.Int32">
<ItemStyle HorizontalAlign="Center" Width="50px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="GroupName" HeaderText="Group Name"
SortExpression="GroupName" UniqueName="GroupName">
<ItemStyle Width="250px" />
<HeaderStyle Width="250px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SortOrder" HeaderText="Sort Order"
SortExpression="SortOrder" UniqueName="SortOrder">
<ItemStyle HorizontalAlign="Center" Width="80px" />
<HeaderStyle HorizontalAlign="Center" Width="80px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ProductionCost" HeaderText="Production Cost"
SortExpression="ProductionCost" UniqueName="ProductionCost" DataFormatString="{0:c2}">
<ItemStyle HorizontalAlign="Center" Width="80px" />
<HeaderStyle HorizontalAlign="Center" Width="80px" />
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings CaptionDataField="GroupName"
CaptionFormatString="Edit Production Group: {0}"
InsertCaption="New Production Group"
EditFormType="Template" >
<EditColumn ButtonType="ImageButton">
</EditColumn>
<PopUpSettings Modal="true" />
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="270" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Group Name:
</td>
<td>
<telerik:RadTextBox ID="TextBox10" Text='<%# Bind("GroupName") %>' runat="server">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
Sort Order:
</td>
<td>
<telerik:RadTextBox ID="TextBox11" Text='<%# Bind("SortOrder") %>' MaxLength="2" runat="server">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
Production Cost:
</td>
<td>
<telerik:RadNumericTextBox ID="txtProductionCost" runat="server" Width="100px" Type="Currency" Text='<%# Bind("ProductionCost") %>'>
<NumberFormat DecimalDigits="2" />
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="left" colspan="2">
<asp:Button ID="Button1"
runat="server" class="rgUpdate" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="Button2" class="rgCancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadPane>
</telerik:RadSplitter>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="DeleteProductionGroup" InsertMethod="InsertProductionGroup"
SelectMethod="GetAllProductionGroups" TypeName="comp.BL.ProductionController"
UpdateMethod="UpdateProductionGroup">
<DeleteParameters>
<asp:Parameter Name="GroupID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="GroupName" Type="String" />
<asp:Parameter Name="sortOrder" Type="Int32" />
<asp:Parameter Name="ProductionCost" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="GroupID" Type="Int32" />
<asp:Parameter Name="GroupName" Type="String" />
<asp:Parameter Name="sortOrder" Type="Int32" />
<asp:Parameter Name="ProductionCost" Type="Decimal" />
</UpdateParameters>
</asp:ObjectDataSource>
aspx.cs
-------
double total_ProductionCost = 0;
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridFooterItem)
{
GridFooterItem footerItem = e.Item as GridFooterItem;
footerItem["ProductionCost"].Text = "" + String.Format("{0:C2}", total_ProductionCost);
}
if (e.Item.ItemType != GridItemType.Item && e.Item.ItemType != GridItemType.AlternatingItem) return;
tblProductionGroup item = (tblProductionGroup)e.Item.DataItem;
if (item.ProductionCost.HasValue)
{
double ProductionCost = (double)item.ProductionCost;
total_ProductionCost += ProductionCost;
}
var source = RadGrid1.DataSource;
}