I have a dynamically created gridview that displays different pieces and their quantity. I want to get the total of these rows to display the total in the units column. So for example the value in the Unit column on the first row should be 190 (12 + 7 + 136 + 35)
The problem is the number of pieces can be different for each user. The example in the image has 13 pieces, but a different user might only have 5.
The units column will always be in the 9th position. So is there a way to check the value of each column after the unit column, till it reaches the end and then add those values together?
EDIT
main.Columns.Add("Units", typeof(int)).SetOrdinal(8);
foreach (DataRow row in main.Rows)
{
int total = 0;
for (int i = 9; i < main.Columns.Count - 1; i++)
{
total += row[i];
}
row["Units"] = total;
}