Monday, May 4, 2009

Showing Gridview Column SUM in FOOTER

Hi All,
This post demonstrates how we can show the SUM of a Particular Column of Gridview in it's FOOTER.

1)Populate Gridview with SQLDATASOURCE.
2).Make Show Footer Property of the Gridview =TRUE
3)On GridView1_RowDataBound event write the below Code:

if (e.Row.RowType == DataControlRowType.DataRow)
sum = sum + Convert.ToInt32(e.Row.Cells[0].Text);
else if (e.Row.RowType == DataControlRowType.Footer)
e.Row.Cells[0].Text = sum.ToString();

Here e.Row.Cells[0].text is shown because I have taken First column as to SUM UP in the Footer :)

And here is the Result...


That's it...and its done.... :)

Thanks,
Nitin Sharma