title: insert data of selected gridview checkboxes values using c# asp.net
body: <p>I am trying to make a meal planner, I have a <code>GridView</code> of foods and their nutritional values and a <code>CheckBox</code> 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. </p>
  
  <p>Here is what I have which is not working:</p>
  
  <pre><code> protected void AddFoodbtn_Click(object sender, EventArgs e)
   {
  
         CheckBox rowcheck = (CheckBox)GridView2.FindControl("SelectFoodchk");
          for (int i = 0; 0 &lt; GridView2.Rows.Count; i++)
          {
              if (rowcheck.Checked)
              {
  
                  GridViewRow viewrow = GridView2.Rows[i];
                  string foodid = viewrow.Cells[0].Text.ToString();
  
  
              }
  
          }
      }
  </code></pre>