Home > DeveloperSection > Forums > How to sum of value in gridview select data from database in asp.net
Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    May-09-2013 4:19 AM

 C# C# 

 1 Reply(s)
 1073  View(s)
Rate this:

I want to display PF and ESI value from basic salary and total PF and ESI in gridview footer in Indian currency. 

Please help me asap.

Thanks in advance! 


Total Post:604

Posted on    May-09-2013 8:04 AM

Hi Takeshi!

You can try as following

you have to write the code in RowDataBound Event of gridview.

I am posting a sample code for your reference try it yourself

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   if (e.Row.RowType == DataControlRowType.DataRow)
      Label lblPrice = (Label)e.Row.FindControl("lblPrice");
      Label lblUnitsInStock = (Label)e.Row.FindControl("lblUnitsInStock");

      decimal price = Decimal.Parse(lblPrice.Text);
      decimal stock = Decimal.Parse(lblUnitsInStock.Text);

      totalPrice += price;
      totalStock += stock;

      totalItems += 1;

   if (e.Row.RowType == DataControlRowType.Footer)
      Label lblTotalPrice = (Label)e.Row.FindControl("lblTotalPrice");
      Label lblTotalUnitsInStock = (Label)e.Row.FindControl("lblTotalUnitsInStock");

      lblTotalPrice.Text = totalPrice.ToString();
      lblTotalUnitsInStock.Text = totalStock.ToString();

      lblAveragePrice.Text = (totalPrice / totalItems).ToString("F");

I hope it resolve your problem

Don't want to miss updates? Please click the below button!

Follow MindStick