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
Suthish NairPosted Nov 6, 2011, 9:50 AM
Rajkumar RPosted Nov 4, 2011, 6:30 AM
Rajkumar RPosted Nov 4, 2011, 6:27 AM
TulasiPosted Nov 4, 2011, 6:08 AM
chk this code it may helps u
Please mark the answer as Accepted if it helps you.
Jean PaulPosted Nov 4, 2011, 5:28 AM
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