Wednesday, January 11, 2012

Calculating Totals in Footer in Gridview example

protected void grdByCarrier_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
double rowpremiumTotal = Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Premium"));
grdPremiumTotal = grdPremiumTotal + rowpremiumTotal;

}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblPremiumTotal = (Label)e.Row.FindControl("lblPremiumTotal");
lblPremiumTotal.Text = grdPremiumTotal.ToString("c");
}
}


Design :




























1 comment: