Jes Sie

Jes Sie

  • 741
  • 1.2k
  • 281.8k

Sum of Gridview colum that has a dynamically added row.

Mar 1 2017 10:16 PM
Before I would ask my nth question, I would like to thank everybody for your help. As an aspiring c# programmer your valued response is really a big help.
 
I'm trying to make a cashiering system. For the details I'm using a gridview with a rows that are dynamically added. Now, I want to get the sum of the column "Amount Paid" but all the codes that I tried failed. Please note that this is a data entry. To make my self clear, I'm attaching an image and my code behind. Thanks in advance for your help.
 
 Below is my code:

  1. decimal amount = 0;
  2. protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)  
  3.         {  
  4.   
  5.             if (e.Row.RowType == DataControlRowType.DataRow)  
  6.             {  
  7.                 decimal amount = Convert.ToDecimal(e.Row.Cells[12].FindControl("txtNetAmountReceived").ToString());  
  8.                 amount += Convert.ToDecimal(amount);  
  9.             }  
  10.   
  11.   
  12.             if (e.Row.RowType == DataControlRowType.Footer)  
  13.             {  
  14.                 Label lblamount = (Label)e.Row.FindControl("lblAmountPaid");  
  15.                 NetPremium.Value = totalPaid.ToString("N2");  
  16.   
  17.             }  
  18.         }  
 

Answers (2)