HOW TO SUM OF VALUE IN GRIDVIEW SELECT DATA FROM DATABASE IN ASP.NET

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
C# 
C#
 1401  View(s)
Ratings:
Rate this:
Hi!

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! 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How to sum of value in gridview select data from database in asp.net

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!