How to sum of value in gridview select data from database in asp.net

Total Post:89

Points:629

C# 
C#
 1790  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. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.