views:

98

answers:

1

Hi guys,

i am using asp.net.In my gridview control i have a column called "TotalAmount".The total amount in this column is to be calculated.How can i do this?

Like this:-

    Col3(TotalAmount)

       30
       40
       30

Total Amount=30+40+30=100

How can i calculate this 100?This is my question.

+1  A: 

I gather you are toalling on a specific row (since you are mentioning it as a total column), i.e.

Val1 | Val2 | Val3 | Total
--------------------------
  10 |   20 |   30 |  60
  5  |    1 |    1 |   7

Then depending on what your datasource is you should either calculate the TotalAmount in your SQL statement or as a property (preferred) in the classes/objects you are binding. Your TotalAmount column is then basically a BoundColumn/Field for that field/property.

Doing the sum is "business logic" and is as such not a job for the GridView.

Class way:

public class MyData
{
    public int Val1 { get; set; }
    public int Val2 { get; set; }
    public int Val3 { get; set; }
    public int TotalAmount { get { return this.Val1 + this.Val2 + this.Val3; } }
}

or whatever your logic is

veggerby
sorry for posting C#, hope you can "abstract" from that
veggerby
i have edited my question.Please see it
Nandini
do u know this,veggerby?
Nandini