hi
i am having a table with values EmpName,EmpCode,InTime,OutTime & Duration
these are displayed in a GridView for the entire month eg 1/1/2011-31/1/2011
but i need to calculate the total InTime,OutTime,Duration and display it in the gridview
as now it is showing daily data i need to sum up all the times and display in the gridview
Loading
Jean PaulPosted Nov 10, 2011, 1:23 AM
You can use an entity approach or grid cell calculation-on-the-fly method. I prefer the first one as it is more readable.
1. You can create a class to represent the values from db.
2. Set the values from datareader
Eg:
IList
while(dr.Read())
list.Add(new SignInInfo() { EmpCode=dr["EmpCode"]});
double grandTotal = GetGrandTotal(list);
3. After that map the above properties to the grid columns
4. Use the following method to calculate the grand total
public double GetGrandTotal(IList
{
double sum = 0;
foreach(SignInInfo info in list)
sum+=info.Duration;
return sum;
}
Please let me know if it works or not.