views:

546

answers:

1
+1  Q: 

GridView For Each

I have a gridview that displays items details, I added two template fields one is a checkbox and the other is a textboc, what I want is simply to check all the items the customer wants to buy, and write down the quantity in the textbox, when I click on a button, I should check all rows in the gridview and when the checkbox is Checked then I should compare the value in the textbox with the value in a databound field of the gridview called Quantity and then carry on my order function...

I know this sounds too much, so any kind of help is deeply appreciated...

+3  A: 

If your question is "How to iterate through a GridView's rows", then my answer is as follows:

int count = gridView1.Rows.Count;

for(int i=0; i < count; i++)
{
  GridViewRow row = gridView1.Rows[i];
  CheckBox cb = row.FindControl("CheckBoxID") as CheckBox;
  //Check if CheckBox is checked
  if(cb != null && cb.Checked) 
  {
    // Logic here.
  }
}
Cerebrus