I have a DataTable that I bind to a gridview on a website. The table has columns of data for several months. I want the user to be able to update the gridview in various ways, for example summing every 12 months (columns) of data. I have accomplished this before by having a foreach loop go through and sum these columns of each row and add it to a table with different columns,
foreach (DataRow dr in data.Rows)
{
newRow[6] = Convert.ToDouble(dr[6]) + Convert.ToDouble(dr[7]) + Convert.ToDouble(dr[8]);
et cetera
newDataTable.Rows.Add(newRow);
}
but I find this takes a while to run.
Is there a more efficient method? Since I have the table with month by month data stored in a session variable. Can I easily pass this to a method that will condense it without having to create a new data table and rebuild it row by row? I'm thinking something along the lines of using DataTable.Select but instead of returning a DataRow[] I would need a DataColumn[] to sum across? I'm not entirely sure.
Maybe there isn't another way, but I was wondering if anyone had any approaches that would be better. Thank you,