C# Gridview Summary total within RowDataBound

  • Thread starter Thread starter LITTIE KILLER
  • Start date Start date
L

LITTIE KILLER

Guest
I am trying to display the summary total at the footer of my grid view. I am using the GridView_RowDataBound that's auto generated when you click into it from the properties menu.
I am able to view the summary total of the gridview in the data when I manually input what the header will be and this works but I want to make it dynamic so it will work with different header.

The code below works and will display the total in the footer but only for "JimsAccount"


int total = 0;
protected void GridViewUser_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow && DataBinder.Eval(e.Row.DataItem, "JimsAccount") != System.DBNull.Value)
{
total +=
Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "JimsAccount"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
System.Diagnostics.Debug.WriteLine("In footer");
e.
Row.Cells[0].Text = "Grand Total";
e.
Row.Cells[0].Font.Bold = true;

e.
Row.Cells[1].Text = total.ToString();
e.
Row.Cells[1].Font.Bold = true;
}

}



To sum up, works when I manually input the headers along with their positions but I can't get it to work dynamically.

Continue reading...
 
Back
Top