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
Loading

Jean PaulRank #32 · 38.5K reputationPosted Nov 4, 2011, 1:28 AM EDT
You can do the following:
if (IsLastPage())
ShowAllPageTotal()
else
ShowCurrentPageTotal()
IsLastPage()
return (GridView1.PageIndex == (GridView1.PageCount - 1));
ShowAllPageTotal()
// Iterate through the datasoure and find the total
ShowCurrentPageTotal()
// Iterate through the current page using PageIndex and PageCount properties and find total
TulasiRank #2,544 · 549 reputationPosted Nov 4, 2011, 2:08 AM EDT
chk this code it may helps u
Please mark the answer as Accepted if it helps you.
Rajkumar R175 reputationPosted Nov 4, 2011, 2:27 AM EDT
Rajkumar R175 reputationPosted Nov 4, 2011, 2:30 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Nov 6, 2011, 4:50 AM EST