Calculated column with total in footer

Thread is closed for posting
12 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 27 Mar 2007 Link to this post

    Requirements

    RadGrid for ASP .NET version

    4.5.2 and later

    .NET version

    2.x

    Visual Studio version

    2005

    Programming language

    C#

    Browser support

    all supported by RadGrid for ASP .NET


    Note: The demonstrated functionality is supported automatically for RadControls for ASP .NET AJAX version 2008.1.415 and later as demonstrated in this online example.
     
    PROJECT DESCRIPTION
    Sometimes it might be a requirement to display a calculated column at the end of each grid row which to show the result of a mathematic operations performed over the data in the relevant row. Furthermore, you may want to sum the values from the calculated column and render the sum in the column footer.

    This is easily attainable hooking the ItemDataBound event of RadGrid and performing the computation there. Below are the code snippets (in C# and VB.NET) taken from the demo application:

        double total;  
     
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                GridDataItem dataItem = e.Item as GridDataItem;  
                (dataItem.FindControl("lblTotal"as Label).Text = (int.Parse(dataItem["Quantity"].Text) * Double.Parse(dataItem["UnitPrice"].Text)).ToString();  
                total += Double.Parse((dataItem.FindControl("lblTotal"as Label).Text);  
            }  
            if (e.Item is GridFooterItem)  
            {  
                GridFooterItem footerItem = e.Item as GridFooterItem;  
                footerItem["Total"].Text = "Total expenses on this page: " + total.ToString();  
            }  
        } 

    Private total As Double   
     
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound  
     If TypeOf e.Item Is GridDataItem Then   
       Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)   
       CType(dataItem.FindControl("lblTotal"), Label).Text = (Integer.Parse(dataItem("Quantity").Text) * Double.Parse(dataItem("UnitPrice").Text)).ToString()   
       total += Double.Parse(CType(dataItem.FindControl("lblTotal"), Label).Text)   
     End If   
     If TypeOf e.Item Is GridFooterItem Then   
       Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem)   
       footerItem("Total").Text = "Total expenses on this page: " + total.ToString()   
     End If   
    End Sub 
  2. CE1E12EA-753F-4968-94D9-9A8F4CB20723
    CE1E12EA-753F-4968-94D9-9A8F4CB20723 avatar
    14 posts
    Member since:
    Feb 2007

    Posted 04 Apr 2007 Link to this post

    Dear admin,

    Is it possible to calculate total in heirarchical grid. If yes, then how and if no, then why.

    I want to show total in footer of MastertableView and GridtableView (inside DetailTable).

    Its Urgent.

    With Regards,
    Venky
  3. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 04 Apr 2007 Link to this post

    Hi Venky,

    I am attaching a modified version of the example web site presenting how to extend the logic for hierarchical grid. The main difference is that you will need to determine the level of the hierarchy on ItemDataBound to compute the calculated column value and display the total in its footer:

        double totalShipCost;  
        double totalExpenses;  
     
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem && e.Item.OwnerTableView.DataSourceID == "AccessDataSource1")  
            {  
                GridDataItem dataItem = e.Item as GridDataItem;  
                string freight = dataItem["Freight"].Text;  
                (dataItem.FindControl("lblTotalMaster"as Label).Text = (Double.Parse(freight) * 2).ToString();  
                totalShipCost += Double.Parse((dataItem.FindControl("lblTotalMaster"as Label).Text);  
            }  
            if (e.Item is GridFooterItem && e.Item.OwnerTableView.DataSourceID == "AccessDataSource1")  
            {  
                GridFooterItem footerItem = e.Item as GridFooterItem;  
                footerItem["TotalMaster"].Text = "Shipping cost on this page: " + totalShipCost.ToString();  
            }  
            if (e.Item is GridDataItem && e.Item.OwnerTableView.DataSourceID == "AccessDataSource2")  
            {  
                GridDataItem dataItem = e.Item as GridDataItem;  
                (dataItem.FindControl("lblTotalDetail"as Label).Text = (int.Parse(dataItem["Quantity"].Text) * Double.Parse(dataItem["UnitPrice"].Text)).ToString();  
                totalExpenses += Double.Parse((dataItem.FindControl("lblTotalDetail"as Label).Text);  
            }  
            if (e.Item is GridFooterItem && e.Item.OwnerTableView.DataSourceID == "AccessDataSource2")  
            {  
                GridFooterItem footerItem = e.Item as GridFooterItem;  
                footerItem["TotalDetail"].Text = "Total expenses for this order: " + totalExpenses.ToString();  
            }  
        } 

    Private totalShipCost As Double 
    Private totalExpenses As Double 
     
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound  
        If TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.DataSourceID = "AccessDataSource1" Then 
            Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)  
            Dim freight As String = dataItem("Freight").Text  
            CType(dataItem.FindControl("lblTotalMaster"), Label).Text = (Double.Parse(freight) * 2).ToString()  
            totalShipCost += Double.Parse(CType(dataItem.FindControl("lblTotalMaster"), Label).Text)  
        End If 
        If TypeOf e.Item Is GridFooterItem AndAlso e.Item.OwnerTableView.DataSourceID = "AccessDataSource1" Then 
            Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem)  
            footerItem("TotalMaster").Text = "Shipping cost on this page: " + totalShipCost.ToString()  
        End If 
        If TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.DataSourceID = "AccessDataSource2" Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
            CType(dataItem.FindControl("lblTotalDetail"), Label).Text = (Integer.Parse(dataItem("Quantity").Text) * Double.Parse(dataItem("UnitPrice").Text)).ToString()  
            totalExpenses += Double.Parse(CType(dataItem.FindControl("lblTotalDetail"), Label).Text)  
        End If 
        If TypeOf e.Item Is GridFooterItem AndAlso e.Item.OwnerTableView.DataSourceID = "AccessDataSource2" Then 
            Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem)  
            footerItem("TotalDetail").Text = "Total expenses for this order: " + totalExpenses.ToString()  
        End If 
    End Sub 

    Best regards,
    Stephen
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
  4. CE1E12EA-753F-4968-94D9-9A8F4CB20723
    CE1E12EA-753F-4968-94D9-9A8F4CB20723 avatar
    14 posts
    Member since:
    Feb 2007

    Posted 05 Apr 2007 Link to this post

    Hi Stephen,

    Thanks for your reply, but its not working in my case. I saw the attached file. Everything is same in both.

    Since there is no option to attach the source files, i'm pasting it here. Please go thru it and send me a reply as soon as possible. Its urgent.

    MSSummaryReport.aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="MSSummaryReport.aspx.vb"

    Inherits="MSSummaryReport" %>

    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %>

    <%@ Register Assembly="RadCalendar.Net2" Namespace="Telerik.WebControls" TagPrefix="radCln" %>

    <%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="radI" %>

    <%@ Register Assembly="RadComboBox.Net2" Namespace="Telerik.WebControls" TagPrefix="radC" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

    <title>Sundari Sales Order System</title>

    </head>

    <body>

    <form id="frmMSSummRep" runat="server">

    <div>

    <table border="2" cellspacing="1" cellpadding="5" style="border-collapse: collapse;

    width: 100%;">

    <tr>

    <td align="left">

    <asp:Label ID="Label2" runat="server" Text="Date"></asp:Label>

    </td>

    </tr>

    </table>

    <table border="2" cellspacing="1" cellpadding="5" style="border-collapse: collapse;

    width: 100%;">

    <tr>

    <td align="center">

    <asp:Label ID="Label3" runat="server" Text="From:"></asp:Label>

    <radCln:RadDatePicker ID="rdtpFrom" runat="server" Width="90px" SelectedDate="" FocusedDate="">

    <PopupButton HoverImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopupHover.gif"

    ImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopup.gif"></PopupButton>

    <Calendar Skin="WebBlue" runat="server">

    </Calendar>

    <DateInput Title="" PromptChar=" " TitleIconImageUrl="" DisplayPromptChar="_" CatalogIconImageUrl=""

    TitleUrl="" Description="" DateFormat="dd/MM/yyyy" Skin="Default"></DateInput>

    <DatePopupButton HoverImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopupHover.gif"

    ImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopup.gif" />

    </radCln:RadDatePicker>

    <br />

    <asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="From Date should be less than To Date"

    ControlToCompare="rdtpFrom" ControlToValidate="rdtpTo" Operator="GreaterThan"

    Type="Date" Enabled="false"></asp:CompareValidator>

    </td>

    <td align="center">

    <asp:Label ID="Label4" runat="server" Text="To:"></asp:Label>

    <radCln:RadDatePicker ID="rdtpTo" runat="server" Width="90px" SelectedDate="" FocusedDate="">

    <PopupButton HoverImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopupHover.gif"

    ImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopup.gif"></PopupButton>

    <Calendar Skin="WebBlue" runat="server">

    </Calendar>

    <DateInput Title="" PromptChar=" " TitleIconImageUrl="" DisplayPromptChar="_" CatalogIconImageUrl=""

    TitleUrl="" Description="" DateFormat="dd/MM/yyyy" Skin="Default"></DateInput>

    <DatePopupButton HoverImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopupHover.gif"

    ImageUrl="~/RadControls/Calendar/Skins/Pink/Img/datePickerPopup.gif" />

    </radCln:RadDatePicker>

    <br />

    <asp:CompareValidator ID="compValDate" runat="server" ErrorMessage="From Date should be less than To Date"

    ControlToCompare="rdtpFrom" ControlToValidate="rdtpTo" Operator="GreaterThanEqual"

    Type="Date"></asp:CompareValidator>

    </td>

    </tr>

    <tr>

    <td colspan="2" align="center">

    <asp:Label ID="Label1" runat="server" Text="Class"></asp:Label>

    <radC:RadComboBox ID="rcmbClass" runat="server" Skin="WindowsGray" SkinsPath="~/RadControls/ComboBox/Skins"

    Width="150px" DataSourceID="sdsClass" DataTextField="Region" DataValueField="Region">

    </radC:RadComboBox>

    </td>

    </tr>

    </table>

    <table border="2" cellspacing="1" cellpadding="5" style="border-collapse: collapse;

    width: 100%;">

    <tr>

    <td align="center">

    <asp:Button ID="cmdView" runat="server" Text="View" BackColor="#FFFFFF" BorderColor="#000000"

    BorderStyle="Ridge" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" />

    </td>

    </tr>

    </table>

    <br />

    <br />

    <table border="2" cellspacing="1" cellpadding="5" style="border-collapse: collapse;

    width: 100%;">

    <tr>

    <td align="left">

    <asp:Label ID="Label5" runat="server" Text="Order Details"></asp:Label>

    </td>

    </tr>

    </table>

    <table border="2" cellspacing="1" cellpadding="5" style="border-collapse: collapse;

    width: 100%;">

    <tr>

    <td align="center">

    <radG:RadGrid ID="rgMSSummRep" runat="server" DataSourceID="sdsMSSummRep" GridLines="None"

    Skin="3D" Width="98%" EnableAJAX="True" ShowFooter="True" FooterStyle-Height="30px">

    <MasterTableView AutoGenerateColumns="False" DataSourceID="sdsMSSummRep" ShowFooter="true">

    <Columns>

    <radG:GridBoundColumn DataField="cust_id" DataType="System.Int32" HeaderText="cust_id"

    SortExpression="cust_id" UniqueName="cust_id" Visible="False">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="Customer" HeaderText="Customer" SortExpression="Customer"

    UniqueName="Customer">

    <HeaderStyle HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="Class" HeaderText="Class" SortExpression="Class"

    UniqueName="Class">

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    <radG:GridTemplateColumn DataType="System.Int32" HeaderText="Order Total" SortExpression="Order Total"

    UniqueName="Order Total">

    <ItemTemplate>

    <asp:Label ID="lblOrdTotal" runat="server" Text='<%# FormatCurrency(DataBinder.Eval(Container.DataItem,"Order Total"),0) %>'></asp:Label>

    </ItemTemplate>

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridTemplateColumn>

    <radG:GridTemplateColumn DataType="System.Int32" HeaderText="MS Total" SortExpression="Marketing Support Total"

    UniqueName="Marketing Support Total">

    <ItemTemplate>

    <asp:Label ID="lblMSTotal" runat="server" Text='<%# FormatCurrency(DataBinder.Eval(Container.DataItem,"Marketing Support Total"),0) %>'></asp:Label>

    </ItemTemplate>

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridTemplateColumn>

    <radG:GridBoundColumn DataField="Marketing Support %" DataType="System.Decimal" HeaderText="MS %"

    ReadOnly="True" SortExpression="Marketing Support %" UniqueName="Marketing Support %">

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    <radG:GridTemplateColumn DataType="System.Int32" HeaderText="Promotion" SortExpression="Promotion Total"

    UniqueName="Promotion Total">

    <ItemTemplate>

    <asp:Label ID="lblSchTotal" runat="server" Text='<%# FormatCurrency(DataBinder.Eval(Container.DataItem,"Promotion Total"),0) %>'></asp:Label>

    </ItemTemplate>

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridTemplateColumn>

    <radG:GridBoundColumn DataField="Promotion %" DataType="System.Decimal" HeaderText="Promotion %"

    ReadOnly="True" SortExpression="Promotion %" UniqueName="Promotion %">

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    </Columns>

    <ExpandCollapseColumn>

    <HeaderStyle Width="19px" />

    </ExpandCollapseColumn>

    <RowIndicatorColumn Visible="False">

    <HeaderStyle Width="20px" />

    </RowIndicatorColumn>

    <DetailTables>

    <radG:GridTableView runat="server" DataSourceID="sdsOrder" AutoGenerateColumns="False"

    ShowFooter="true">

    <ParentTableRelation>

    <radG:GridRelationFields DetailKeyField="id" MasterKeyField="cust_id" />

    </ParentTableRelation>

    <Columns>

    <radG:GridBoundColumn DataField="id" HeaderText="id" UniqueName="id" Visible="False">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="Order Number" HeaderText="Order Number" UniqueName="Order Number">

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle Width="80px" HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    <radG:GridTemplateColumn DataType="System.Int32" HeaderText="Order Total" SortExpression="Order Total"

    UniqueName="Order Total">

    <ItemTemplate>

    <asp:Label ID="lblOrdTotal" runat="server" Text='<%# FormatCurrency(DataBinder.Eval(Container.DataItem,"Order Total"),0) %>'></asp:Label>

    </ItemTemplate>

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridTemplateColumn>

    <radG:GridTemplateColumn DataType="System.Int32" HeaderText="MS Total" SortExpression="Marketing Support Total"

    UniqueName="Marketing Support Total">

    <ItemTemplate>

    <asp:Label ID="lblMSTotal" runat="server" Text='<%# FormatCurrency(DataBinder.Eval(Container.DataItem,"Marketing Support Total"),0) %>'></asp:Label>

    </ItemTemplate>

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridTemplateColumn>

    <radG:GridBoundColumn DataField="Marketing Support %" HeaderText="MS %" UniqueName="Marketing Support %">

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    <radG:GridTemplateColumn DataType="System.Int32" HeaderText="Promotion" SortExpression="Promotion Total"

    UniqueName="Promotion Total">

    <ItemTemplate>

    <asp:Label ID="lblSchTotal" runat="server" Text='<%# FormatCurrency(DataBinder.Eval(Container.DataItem,"Promotion Total"),0) %>'></asp:Label>

    </ItemTemplate>

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridTemplateColumn>

    <radG:GridBoundColumn DataField="Promotion %" HeaderText="Promotion %" UniqueName="Promotion %">

    <HeaderStyle HorizontalAlign="Center" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridBoundColumn>

    </Columns>

    <ExpandCollapseColumn Visible="False">

    <HeaderStyle Width="19px" />

    </ExpandCollapseColumn>

    <RowIndicatorColumn Visible="False">

    <HeaderStyle Width="20px" />

    </RowIndicatorColumn>

    </radG:GridTableView>

    </DetailTables>

    </MasterTableView>

    <FooterStyle Height="30px" />

    </radG:RadGrid>

    </td>

    </tr>

    </table>

    <asp:SqlDataSource ID="sdsMSSummRep" runat="server" ConnectionString="<%$ ConnectionStrings:SundariConn %>"

    SelectCommand="SELECT Convert(decimal(18,0),SUM(order_value)) 'Order Total', Convert(decimal(18,0),SUM(ms_value)) 'Marketing Support Total', Convert(decimal(18,0),SUM(scheme_value)) 'Promotion Total', cust_id, Customer, Class, CONVERT(decimal(18, 2), CASE SUM(order_value) WHEN 0 THEN 0 ELSE (SUM(ms_value) / SUM(order_value) * 100) END) 'Marketing Support %', CONVERT(decimal(18, 2), CASE SUM(order_value) WHEN 0 THEN 0 ELSE (SUM(scheme_value) / SUM(order_value) * 100) END) 'Promotion %' FROM (SELECT B.id 'cust_id', B.delivery_to 'Customer', B.class 'Class', SUM(CASE C.prod_type WHEN 'A' THEN C.prod_amount ELSE 0 END) AS order_value, SUM(CASE C.prod_type WHEN 'B' THEN C.prod_amount ELSE 0 END) AS ms_value, SUM(CASE C.prod_type WHEN 'S' THEN C.prod_amount ELSE 0 END) AS scheme_value FROM sundari_sof_master A INNER JOIN sundari_customer_master B ON A.cust_id = B.id INNER JOIN sundari_sof_products C ON A.id = C.invoice_number WHERE (A.approved = 'y') and B.class = @Class and A.po_date between @DateFrom and @DateTo GROUP BY B.delivery_to, B.class, A.cust_id, A.invoice_number, C.prod_type, B.id)tab GROUP BY cust_id, Customer, Class ORDER BY Customer">

    <SelectParameters>

    <asp:ControlParameter ControlID="rcmbClass" Name="Class" PropertyName="SelectedValue" />

    <asp:ControlParameter ControlID="rdtpFrom" Name="DateFrom" PropertyName="SelectedDate" />

    <asp:ControlParameter ControlID="rdtpTo" Name="DateTo" PropertyName="SelectedDate" />

    </SelectParameters>

    </asp:SqlDataSource>

    <asp:SqlDataSource ID="sdsClass" runat="server" ConnectionString="<%$ ConnectionStrings:SundariConn %>"

    SelectCommand="SELECT [region], [id] FROM [sundari_regionmaster]"></asp:SqlDataSource>

    <asp:SqlDataSource ID="sdsOrder" runat="server" ConnectionString="<%$ ConnectionStrings:SundariConn %>"

    SelectCommand="SELECT id, invoice_number 'Order Number', CONVERT(decimal(18, 0), SUM(order_value)) 'Order Total', CONVERT(decimal(18, 0), SUM(ms_value)) 'Marketing Support Total', CONVERT(decimal(18, 0), SUM(scheme_value)) 'Promotion Total', cust_id, CONVERT(decimal(18, 2), CASE SUM(order_value) WHEN 0 THEN 0 ELSE (SUM(ms_value) / SUM(order_value) * 100) END) 'Marketing Support %', CONVERT(decimal(18, 2), CASE SUM(order_value) WHEN 0 THEN 0 ELSE (SUM(scheme_value) / SUM(order_value) * 100) END) 'Promotion %' FROM (SELECT A.id, B.id 'cust_id', A.invoice_number, SUM(CASE C.prod_type WHEN 'A' THEN C.prod_amount ELSE 0 END) AS order_value, SUM(CASE C.prod_type WHEN 'B' THEN C.prod_amount ELSE 0 END) AS ms_value, SUM(CASE C.prod_type WHEN 'S' THEN C.prod_amount ELSE 0 END) AS scheme_value FROM sundari_sof_master A INNER JOIN sundari_customer_master B ON A.cust_id = B.id INNER JOIN sundari_sof_products C ON A.id = C.invoice_number WHERE (A.approved = 'y') AND A.po_date BETWEEN @FromDate AND @ToDate AND B.id = @Cust_ID GROUP BY A.cust_id, A.invoice_number, C.prod_type, B.id, A.id) tab GROUP BY cust_id, invoice_number, id ORDER BY invoice_number">

    <SelectParameters>

    <asp:ControlParameter ControlID="rdtpFrom" Name="FromDate" PropertyName="SelectedDate" />

    <asp:ControlParameter ControlID="rdtpTo" Name="ToDate" PropertyName="SelectedDate" />

    <asp:SessionParameter Name="Cust_ID" SessionField="Cust_ID" />

    </SelectParameters>

    </asp:SqlDataSource>

    </div>

    </form>

    </body>

    </html>


    MSSummaryReport.aspx.vb

    Imports System.Data

    Imports System.Data.SqlClient

    Imports Telerik.WebControls

    Partial Class MSSummaryReport

    Inherits System.Web.UI.Page

    Dim i As Integer

    Dim orderTotal As Integer = 0

    Dim msTotal As Integer = 0

    Dim schTotal As Integer = 0

    Dim msPercent As Decimal = 0

    Dim schPercent As Decimal = 0

    Dim temp As Decimal

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then

    rdtpFrom.SelectedDate = CDate(CDate(Date.Now.Month.ToString & "/1/" & Date.Now.Year.ToString).ToString("MM/dd/yyyy"))

    rdtpTo.SelectedDate = Date.Now

    End If

    End Sub

    Protected Sub rgMSSummRep_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.WebControls.GridDetailTableDataBindEventArgs) Handles rgMSSummRep.DetailTableDataBind

    Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)

    If Not parentItem.Edit Then

    If (e.DetailTableView.DataSourceID = "sdsOrder") Then

    Session("Cust_ID") = parentItem("cust_id").Text

    End If

    End If

    End Sub

    Protected Sub rgMSSummRep_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles rgMSSummRep.ItemDataBound

    If (TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.DataSourceID = "sdsMSSummRep") Then

    Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)

    If CType(dataItem.FindControl("lblOrdTotal"), Label).Text.Trim = "$0" Then

    CType(dataItem.FindControl("lblOrdTotal"), Label).Text = "--"

    Else

    orderTotal = orderTotal + Decimal.Parse(Right(CType(dataItem.FindControl("lblOrdTotal"), Label).Text, CType(dataItem.FindControl("lblOrdTotal"), Label).Text.Length - 1))

    End If

    If CType(dataItem.FindControl("lblMSTotal"), Label).Text.Trim = "$0" Then

    CType(dataItem.FindControl("lblMSTotal"), Label).Text = "--"

    Else

    msTotal = msTotal + Decimal.Parse(Right(CType(dataItem.FindControl("lblMSTotal"), Label).Text, CType(dataItem.FindControl("lblMSTotal"), Label).Text.Length - 1))

    End If

    If dataItem("Marketing Support %").Text.Trim = "0.00" Then

    dataItem("Marketing Support %").Text = "--"

    Else

    msPercent = msPercent + Decimal.Parse(dataItem("Marketing Support %").Text)

    End If

    If CType(dataItem.FindControl("lblSchTotal"), Label).Text.Trim = "$0" Then

    CType(dataItem.FindControl("lblSchTotal"), Label).Text = "--"

    Else

    schTotal = schTotal + Decimal.Parse(Right(CType(dataItem.FindControl("lblSchTotal"), Label).Text, CType(dataItem.FindControl("lblSchTotal"), Label).Text.Length - 1))

    End If

    If dataItem("Promotion %").Text.Trim = "0.00" Then

    dataItem("Promotion %").Text = "--"

    Else

    schPercent = schPercent + Decimal.Parse(dataItem("Promotion %").Text)

    End If

    If (TypeOf e.Item Is GridFooterItem AndAlso e.Item.OwnerTableView.DataSourceID = "sdsMSSummRep") Then

    Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem)

    footerItem("Customer").Text = "Total"

    footerItem("Order Total").Text = FormatCurrency(orderTotal.ToString, 0)

    footerItem("Marketing Support Total").Text = FormatCurrency(msTotal.ToString, 0)

    footerItem("Marketing Support %").Text = FormatCurrency(msPercent.ToString)

    footerItem("Promotion Total").Text = FormatCurrency(schTotal.ToString, 0)

    footerItem("Promotion %").Text = FormatCurrency(schPercent.ToString)

    End If

    End If

    If (TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.DataSourceID = "sdsOrder") Then

    Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)

    If CType(dataItem.FindControl("lblOrdTotal"), Label).Text.Trim = "$0" Then

    CType(dataItem.FindControl("lblOrdTotal"), Label).Text = "--"

    Else

    orderTotal = orderTotal + Decimal.Parse(Right(CType(dataItem.FindControl("lblOrdTotal"), Label).Text, CType(dataItem.FindControl("lblOrdTotal"), Label).Text.Length - 1))

    End If

    If CType(dataItem.FindControl("lblMSTotal"), Label).Text.Trim = "$0" Then

    CType(dataItem.FindControl("lblMSTotal"), Label).Text = "--"

    Else

    msTotal = msTotal + Decimal.Parse(Right(CType(dataItem.FindControl("lblMSTotal"), Label).Text, CType(dataItem.FindControl("lblMSTotal"), Label).Text.Length - 1))

    End If

    If dataItem("Marketing Support %").Text.Trim = "0.00" Then

    dataItem("Marketing Support %").Text = "--"

    Else

    msPercent = msPercent + Decimal.Parse(dataItem("Marketing Support %").Text)

    End If

    If CType(dataItem.FindControl("lblSchTotal"), Label).Text.Trim = "$0" Then

    CType(dataItem.FindControl("lblSchTotal"), Label).Text = "--"

    Else

    schTotal = schTotal + Decimal.Parse(Right(CType(dataItem.FindControl("lblSchTotal"), Label).Text, CType(dataItem.FindControl("lblSchTotal"), Label).Text.Length - 1))

    End If

    If dataItem("Promotion %").Text.Trim = "0.00" Then

    dataItem("Promotion %").Text = "--"

    Else

    schPercent = schPercent + Decimal.Parse(dataItem("Promotion %").Text)

    End If

    If (TypeOf e.Item Is GridFooterItem AndAlso e.Item.OwnerTableView.DataSourceID = "sdsOrder") Then

    Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem)

    footerItem("Customer").Text = "Total"

    footerItem("Order Total").Text = FormatCurrency(orderTotal.ToString, 0)

    footerItem("Marketing Support Total").Text = FormatCurrency(msTotal.ToString, 0)

    footerItem("Marketing Support %").Text = FormatCurrency(msPercent.ToString)

    footerItem("Promotion Total").Text = FormatCurrency(schTotal.ToString, 0)

    footerItem("Promotion %").Text = FormatCurrency(schPercent.ToString)

    End If

    End If

    End Sub

    End Class

  5. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 05 Apr 2007 Link to this post

    Hello Venky,

    Does the sample project enclosed to my previous post works normally on your end? Since the code library section on our site is dedicated for providing code samples for the community members, I have to ask you start a new support ticket and attach a small runnable version of your project to it. I will test it locally and will do my best to give you an accurate resolution.

    Regards,
    Stephen
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
  6. 8457A4FA-784C-4A4A-8B4B-D33FA82168FD
    8457A4FA-784C-4A4A-8B4B-D33FA82168FD avatar
    5 posts
    Member since:
    Oct 2006

    Posted 04 Jul 2007 Link to this post

    Super!

    Thanks so much!

    Peter
  7. CDD728CA-A977-4A8A-BABA-2ACE95539487
    CDD728CA-A977-4A8A-BABA-2ACE95539487 avatar
    3 posts
    Member since:
    Aug 2007

    Posted 21 Nov 2007 Link to this post

    Hi, I'm trying to understand this sample. So far so good ....it seems not too difficult, rather straight forward ... however. Runtime versions of the RadControl in this sample and what the one I use are the same, however the version of this sample is 4.5.2.0 and the one I use is 4.6.2.0 ( .. a little bit newer isn't it? could this be the problem, I can hardly believe that ..).
    The problem which I cannot solve is that according to the sample part:

    CType(dataItem.FindControl("lblTotal"), Label).Text = (Double.Parse(dataItem("Amount").Text)).ToString()

    The ''Amount'' is the UniqueName of the GridTemplateColumn and in the Datafield is loaded myObject.Amount (type double)

    I cannot solve the error saying:
    System.FormatException was unhandled by user code
    Message=(however translated) "The order of input characters is not correct."
    Source="mscorlib"

    without trying to calculate the total amount the grid is shown fine with several amounts (with decimal numbers as well) ... I tried also to add a second argument (globalization.numberstyles.allowdecimalPoint) but it did not solve anything ..

    Any suggestion?

  8. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 21 Nov 2007 Link to this post

    Hi KWHJ,

    The project from this thread should work with subsequent versions of our web grid as well as with the latest version 5.0.1 of the control. You can check by updating the grid dll in the demo site.

    Regarding the exception you receive:
    This is a generic ASP.NET error message and the reason for it can be that the value you are trying to parse is not in the correct format. I suggest you review these resources to solve the issue you are facing:

    http://www.vbforums.com/archive/index.php/t-397223.html

    http://forums.asp.net/t/992513.aspx

    Kind regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. C041E835-E494-495F-A2C2-612028E49DBA
    C041E835-E494-495F-A2C2-612028E49DBA avatar
    37 posts
    Member since:
    Mar 2007

    Posted 12 Dec 2007 Link to this post

    Can this work for a self-referencing hierarchal grid?
  10. FE7977D3-8E1C-418E-AD04-EA6D5106F9CE
    FE7977D3-8E1C-418E-AD04-EA6D5106F9CE avatar
    3253 posts
    Member since:
    Sep 2018

    Posted 14 Dec 2007 Link to this post

    Hello jalmto,

    The tricky part in calculating totals in self-referencing grid is that we need some how to store levels' totals. As we don't know how many levels the RadGrid is having nor we can use datasource names (as there is only one datasource) to distinguish where we are in hierarchy. Therefore in attached example I have used hashtable to store level's totals and as keys I used item ownerTable's id. Then in footer template I traverse all items in hashtable to find items which key starts with current items ownerTable id. As this will give me all child levels.

    All the best,
    Rosen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. C041E835-E494-495F-A2C2-612028E49DBA
    C041E835-E494-495F-A2C2-612028E49DBA avatar
    37 posts
    Member since:
    Mar 2007

    Posted 14 Dec 2007 Link to this post

    This works PERFECT! PERFECT! PERFECT!
    Thank you!
  12. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 01 Apr 2008 Link to this post

    Hi guys,

    We would like to inform you that this feature is already built-in in the Prometheus version of RadGrid and you can find more details about it here:

    What is new in RadGrid Prometheus

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.