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

how to caluclate the totals in the footer row of the Rad Grid

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sumanth
Top achievements
Rank 2
sumanth asked on 09 Mar 2009, 10:42 AM
Hi
I am Working on Rad Grid
I am bale to caluclate the numarical(int) values totals in footter 
BUT Problem araised in Money Datatype Coloumn
When i trying to caluclate the total for money datatype coloumn
It is dispalying the  all coloumn values in footter(not the SUM Values)
Plz help out to solve the problem
Thanks in advance

here is my C# Code

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using Telerik.Web.UI;

namespace ajaxKrunchBox
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

    
        protected void Button1_Click(object sender, EventArgs e)
        {

            Session["weekend"] = TextBox1.Text;
            Session["status"] = DropDownList4.Text;
            SqlCommand cmd = new SqlCommand("usp_CustomerPerformance_V2", new SqlConnection("Data Source=vijay;Initial Catalog=ULTIMATE_NEW;Integrated Security=True"));
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@Customer", DropDownList1.Text));
            cmd.Parameters.Add(new SqlParameter("@WeekEnding", TextBox1.Text));
            cmd.Parameters.Add(new SqlParameter("@Status", DropDownList4.Text));
            cmd.Parameters.Add(new SqlParameter("@noOfWks", DropDownList3.Text));
            cmd.Connection.Open();
            RadGrid1.DataSourceID = null;
            RadGrid1.DataSource = cmd.ExecuteReader();
            //Session["variable1"] = DropDownList1.Text;
            Session["varibale2"] = TextBox1.Text;
            Session["varibale4"] = DropDownList4;
            Session["varibale3"] = DropDownList3;
            RadGrid1.DataBind();
            RadGrid1.Visible = true;
           
          
            cmd.Connection.Close();
            cmd.Connection.Dispose();
          
        }

        int total1;
        int total2;
        int total3;
        int total4;
        int total5;
        int total6;
        String  total7;
        String total8;
        int total9;
        int total10;
         protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                int fieldValue1 = int.Parse(dataItem["TYWkSales"].Text);
                total1 += fieldValue1;
                int fieldvalue2 = int.Parse(dataItem["LYWkSales"].Text);
                total2 += fieldvalue2;
                int fieldvalue3 = int.Parse(dataItem["TYL4WkSales"].Text);
                total3 += fieldvalue3;
                int fieldvalue4 = int.Parse(dataItem["LYL4WkSales"].Text);
                total4 += fieldvalue4;
                //int fieldvalue5 = int.Parse(dataItem["TYWkRRP"].Text);
                //total5 += fieldvalue5;
                //int fieldvalue6 = int.Parse(dataItem["LYWkRRP"].Text);
                //total6 += fieldvalue6;
                String fieldvalue7 = String.Format(dataItem["TYL4WkRRP"].Text);
                total7 += fieldvalue7;
                mydatatable
                //String fieldvalue8 = String.Format(dataItem["LYL4WkRRP"].Text);
                //total8 += fieldvalue8;
               
                int fieldvalue9 = int.Parse(dataItem["TYWkSOH"].Text);
                total9 += fieldvalue9;
                int fieldvalue10 = int.Parse(dataItem["LYWkSOH"].Text);
                total10 += fieldvalue10;
              
            }
            if (e.Item is GridFooterItem)
            {
                GridFooterItem footerItem = e.Item as GridFooterItem;
                footerItem["TYWkSales"].Text = "Total Units: " + total1.ToString();
                footerItem["LYWkSales"].Text = "Total Units: " + total2.ToString();
                footerItem["TYL4WkSales"].Text = "Total Units: " + total3.ToString();
                footerItem["LYL4WkSales"].Text = "Total Units: " + total4.ToString();
                //footerItem["TYWkRRP"].Text = "Total Price: " + total5.ToString();
                //footerItem["LYWkRRP"].Text = "Total Price: " + total6.ToString();
                footerItem["TYL4WkRRP"].Text = "Total Price: " + total7;
                footerItem["LYL4WkRRP"].Text = "Total Price: " + total8;
                footerItem["TYWkSOH"].Text = "Total Units: " + total9.ToString();
                footerItem["LYWkSOH"].Text = "Total Units: " + total10.ToString();
            }

           

            }
      
       

      

      

    }
}

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 09 Mar 2009, 02:34 PM
Hello sumanth,

The following example demonstrates one possible approach.
I hope it gets you started properly.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
sumanth
Top achievements
Rank 2
Answers by
Yavor
Telerik team
Share this question
or