Problem related with array

Posted by Amritha444 under C# on 12/23/2010 | Points: 10 | Views : 4062 | Status : [Member] | Replies : 1
Hi all

I want to bind all employees salary details in gridview that works fine.but i want sum of all allowance and deductions below that grid.Bind all allowance and deduction in grid using loop according to selection
coding is
DataTable dttype = objtype.GetGridRecords();
if (dttype.Rows.Count > 0)
for (int j = 0; j < dttype.Rows.Count; j++)
string colname = "B_" + dttype.Rows[j]["ShortName"].ToString();
//* set values in the columns of table by payroll types *//
dr[colname] = GetPayTypeAmountLOP(ids, Convert.ToInt64(dttype.Rows[j]["PayTypeID"]));
//To get sum of each allowance
Beforepaytype [j] = Beforepaytype[j] +Convert.ToDecimal( GetPayTypeAmountLOP(ids, Convert.ToInt64(dttype.Rows[j]["PayTypeID"])));



How to display its result.i use the concept to get sum in row
DataTable dttypeloop = objtype.GetGridRecords();
for (int a = 0; a < dttypeloop.Rows.Count; a++)

for (int j = 0; j < Beforepaytype.Length; j++)

string colname = "B_" + dttypeloop.Rows[a]["ShortName"].ToString();
//* set values in the columns of table by payroll types *//

dr[colname] = Beforepaytype[j].ToString();


But didnt get output .Want to declare two dimensional array?

Thanks in advance


Posted by: T.saravanan on: 12/23/2010 [Member] [MVP] Silver | Points: 25

Hi Amritha444,

Do you want to sum value of any column means just use the compute method in datatable.
Try the following code...

string strResult =dtData.Compute("sum(ColumnName)",string.Empty).ToString();

To get total value in that string object.

Refer this link...

Cheers :)


Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response