Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi friends,
i am stuck in my development,
i have a column named quanity in Gridview and another column name Price per Unit,
Total in which value=quantity*PricePerUnit;
but i have a TextChanged Event for Quantity textbox on which calculation is done and displayed in total Column of Gridview.

now i want the Sum of (Total) Column in GridviewFooter. as i enter the value in Quantity of any row in Gridview.

need help

regards
Aamir
Posted

This code will help you:-
C#
 int total = 0;
protected void girdview_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
  if(e.Row.RowType == DataControlRowType.DataRow)
  {
    total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Amount_column"));
   }
  if(e.Row.RowType == DataControlRowType.Footer)
  {
    Label lblAmount = (Label)e.Row.FindControl("amountLabe");
    lblAmount.Text = total.ToString();
  }
}


Good luck.
 
Share this answer
 
v2
You need to keep the track of total per row in RowDataBound event. At the end, assign the total to the footer template total field.

Have a look here: MSDN: GridView Examples for ASP.NET 2.0: Displaying Summary Data in the Footer[^]

Go through it, learn and try out.
 
Share this answer
 
Dear friends,
i am getting the following error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'total'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900