Pages

Saturday, November 27, 2010

Total in Footer_Gridview


------------------------------------------------------------


1.



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

 

CodeAddict.com | Copyright 2009 Tüm Haklar? Sakl?d?r | Free Blogger Templates by GoogleBoy Download Free Wordpress Templates. Unblock through unblock myspace proxy, Hillsongs by Guitar Song Chords