Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i'm new at this posting thing so here goes...
I've got a datagrid with some amounts in one row and a checkbox in another. I also have a calculate button. When i click the calculate button, i want the code to go through the datagrid and calculate the amounts of each row that has been checked in the checkbox, if a checkbox is not checked, it should not use that amount. I'm stumped, but here's the coding i've got so far. It's called from the button on_Click event:

foreach (GridViewRow rows in dgServices.Rows)
           {
               CheckBox cb = (CheckBox)rows.FindControl"cbAddTo");
               if (cb.Checked == true)
               {
                   CalculatedItem += float.Parse(dgServices.Rows[0].Cells[8].Text);
               //here's the problem in the .Rows[0]
}
               else
               {
          //do nothing
               }

               txtTB4V.Text = CalculatedItem.ToString();
           }

so basically i need to know if i'm on the right track or if there's an easier way to do this. Thanks in advance :)

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 29-Apr-11 23:17pm
v2
Comments
tulasiram3975 30-Apr-11 5:17am    
Take One int value and Place in row[int value] increment for every iteration

1 solution

Why not just use the loop variable: "rows"
CalculatedItem += float.Parse(rows.Cells[8].Text);
 
Share this answer
 
Comments
RaviRanjanKr 30-Apr-11 5:26am    
Nice! 5ed
Ace_Hardlight 30-Apr-11 5:48am    
thank you so much! That worked perfectly i just had to set CalculatedItem = 0 at the beginning of the code block.
OriginalGriff 30-Apr-11 5:49am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900