Friday, March 18, 2011

Calculate Sum Column Values and Show in Grid View Footer

protected void myview_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                _DueAmount = _DueAmount + Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Due")); // Due is DataField
                _NetAmount = _NetAmount + Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "NetAmount")); // NetAmount is DataField
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[7].Text = "Total Rs: ";
                e.Row.Cells[8].Text = Convert.ToString(_DueAmount);
                e.Row.Cells[9].Text = Convert.ToString(_NetAmount);               
            }
        }

No comments:

Post a Comment