0

I am trying to make a meal planner, I have a GridView of foods and their nutritional values and a CheckBox row. I want to be able to check as many foods as I wish. Then click the Add Food button and have the information of the checked rows inserted into my database.

Here is what I have which is not working:

 protected void AddFoodbtn_Click(object sender, EventArgs e)
 {

       CheckBox rowcheck = (CheckBox)GridView2.FindControl("SelectFoodchk");
        for (int i = 0; 0 < GridView2.Rows.Count; i++)
        {
            if (rowcheck.Checked)
            {

                GridViewRow viewrow = GridView2.Rows[i];
                string foodid = viewrow.Cells[0].Text.ToString();


            }

        }
    }
Leigh
  • 28,765
  • 10
  • 55
  • 103
user2430175
  • 1
  • 1
  • 1
  • 1
    And how exactly is it not working? Do you get an error message? If so, on what line? Or does it simply do nothing? – Geeky Guy May 28 '13 at 21:09

1 Answers1

0
foreach (GridViewRow row in grid.Rows)
{
   if (((CheckBox)row.FindControl("chkboxid")).Checked)
   {
       //read the label
   }
}

Looping through GridView rows and Checking Checkbox Control

Community
  • 1
  • 1