Sum Columns Grid

6 posts, 1 answers
  1. Hector Hernandez
    Hector Hernandez avatar
    45 posts
    Member since:
    Oct 2009

    Posted 20 Apr 2014 Link to this post

    Hello.

    I have this issue i have grid that i modify data with the event ItemDataBound how can i get the sum and put in the footer of the grid of thes columns, since i dont populate this columns with NeedDataSource

    Thanks in advence
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 21 Apr 2014 Link to this post

    Hello,

    Please try with the below code snippet.

    foreach (GridFooterItem footeritem in RadGrid1.MasterTableView.GetItems(GridItemType.Footer))
    {
        //Access TemplateColumn's Control
        TextBox textbox = (TextBox)footeritem.FindControl("YourTextBoxID");
     
        //Access bound column
        footeritem["YOurColumnUNiqueName"].Text = "Your Value";
    }
     
    //OR
     
    GridFooterItem footeritem =  (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
    if(GridFooterItem != null)
    {
        //Access TemplateColumn's Control
        TextBox textbox = (TextBox)footeritem.FindControl("YourTextBoxID");
     
        //Access bound column
        footeritem["YOurColumnUNiqueName"].Text = "Your Value";
    }

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 21 Apr 2014 in reply to Jayesh Goyani Link to this post

    Hello,

    You can write above code snippet in either in page_Prerender event or in Radgrid_Prerender event.

    Thanks,
    Jayesh Goyani
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Apr 2014 in reply to Hector Hernandez Link to this post

    Hi Hector Hernandez,

    You can set the sum of a column at footer text in the ItemDataBound event as follows:

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound" ShowFooter="true" >

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        int total = 0;
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            int fieldValue = int.Parse(dataItem["ColumnUniqueName"].Text);
            total = total + fieldValue;
        }
        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = (GridFooterItem)e.Item;
            footerItem["ColumnUniqueName"].Text = "Total: " + total.ToString();
        }
    }

    Thanks,
    Shinu
  6. Hector Hernandez
    Hector Hernandez avatar
    45 posts
    Member since:
    Oct 2009

    Posted 22 Apr 2014 in reply to Shinu Link to this post

    Thank you Jayesh
    Work great.

  7. Hector Hernandez
    Hector Hernandez avatar
    45 posts
    Member since:
    Oct 2009

    Posted 22 Apr 2014 Link to this post

    Thank you Shinu!!
    Wonderfull!!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017