There are many occassions when you need to find the total of a particular column in a datagrid and display it in the footer as shown in the figure.
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.AlternatingItem e.Item.ItemType==ListItemType.Item)
{
total+= double.Parse(e.Item.Cells[1].Text);
}
if(e.Item.ItemType==ListItemType.Footer)
{
e.Item.Cells[0].Text="Total";
e.Item.Cells[1].Text=total.ToString();
}
}