We are using RowDataBound event to perform summation in footer row.
we will show you how to display a summary or the sum of values in a particular column, in the GridView footer row. Also known as running total of a column, these accumulated figures needs to be displayed below all the pages, if GridView Paging is set as “True”.
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TotalsCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotaloCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalcCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalSaCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalCAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalPAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalAfAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = string.Format("{0:N0}", TotalsentCnt);
e.Row.Cells[3].Text = string.Format("{0:N0}", TotalopenCnt);
e.Row.Cells[4].Text = string.Format("{0:N0}", TotalclickCnt);
e.Row.Cells[5].Text = string.Format("{0:N0}", TotalSalesCnt);
e.Row.Cells[6].Text = string.Format("{0:C2}", TotalAmt);
e.Row.Cells[7].Text = string.Format("{0:C2}", TotalCustomerAmt);
e.Row.Cells[8].Text = string.Format("{0:C2}", TotalPublisherAmt);
e.Row.Cells[9].Text = string.Format("{0:C2}", TotalAffiliateAmt);
}
}
catch (Exception ex)
{
throw ex;
}
}
we will show you how to display a summary or the sum of values in a particular column, in the GridView footer row. Also known as running total of a column, these accumulated figures needs to be displayed below all the pages, if GridView Paging is set as “True”.
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TotalsCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotaloCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalcCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalSaCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalCAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalPAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
TotalAfAmt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = string.Format("{0:N0}", TotalsentCnt);
e.Row.Cells[3].Text = string.Format("{0:N0}", TotalopenCnt);
e.Row.Cells[4].Text = string.Format("{0:N0}", TotalclickCnt);
e.Row.Cells[5].Text = string.Format("{0:N0}", TotalSalesCnt);
e.Row.Cells[6].Text = string.Format("{0:C2}", TotalAmt);
e.Row.Cells[7].Text = string.Format("{0:C2}", TotalCustomerAmt);
e.Row.Cells[8].Text = string.Format("{0:C2}", TotalPublisherAmt);
e.Row.Cells[9].Text = string.Format("{0:C2}", TotalAffiliateAmt);
}
}
catch (Exception ex)
{
throw ex;
}
}
No comments:
Post a Comment