Rajkumar R

Rajkumar R

  • NA
  • 183
  • 220.5k

Grid view footer total in asp.net

Nov 4 2011 2:51 AM
 protected void inderGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    { 
decimal grdtotal1 = 0; // This is global variable i declared in class
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            decimal rowTotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "DC_No_Decimal"));
            if (e.Row.DataItemIndex >= inderGrid.PageIndex * inderGrid.PageSize && e.Row.DataItemIndex < inderGrid.PageIndex * inderGrid.PageSize + inderGrid.PageSize)
            {
                grdTotal = grdTotal + rowTotal;              
                grdtotal1 = grdTotal;
            }
        }
else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Text = "Totals:";
            // for the Footer, display the running totals
            e.Row.Cells[3].Text = grdTotal.ToString("c");
            // e.Row.Cells[2].Text = quantityTotal.ToString("d");        
            e.Row.Cells[1].HorizontalAlign = e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Font.Bold = true;
        }
}

The above code display total in every page of the gridview. I need total at the end of the grid. My grid contain 20 pages , from that 20 page  i want to display the total in the 20th page by adding all of the pages. Please help me its urgent




Attachment: sample1.zip

Answers (5)