To Show Gridview Total on Current Page
protected void GridView1_DataBound(object sender, EventArgs e)
{
decimal valueInStock = 0;
foreach (GridViewRow row in GridView1.Rows)
{
decimal price = Decimal .Parse(row.Cells[2].Text.Substring(1));
int unitsInStock = Int32 .Parse(row.Cells[3].Text);
valueInStock += price * unitsInStock;
}
GridViewRow footer = GridView1.FooterRow;
footer.Cells[0].ColumnSpan = 3;
footer.Cells[0].HorizontalAlign = HorizontalAlign .Center;
footer.Cells.RemoveAt(2);
footer.Cells.RemoveAt(1);
footer.Cells[0].Text = "Total value in stock (on this page): "+ valueInStock.ToString("C" );
}
0 comments:
Post a Comment