title: implementing CheckBox check in GridView with ASP.NET (C#)
body: <p>Greetigs fellow programmers!
  I have a question for you about the implementation of a CheckBox check across a Gridview.
  First of all, the Gridview is binded to a different datasource according to the querystring that links to the page. This is working so far, i see different elements by different querystrings. 
  What the problem is, and i cannot yet detect how to fix, is that if i select let's say 3 out of 4 checkboxes and press and button that verifies the selections (writes selections to textbox), the program AUTOMATICALLY CHECKS ALL the checkboxes and gives me all the values (which i don't need) . I browsed for answers but could not find something similar (or i didn't search good enough,w/e).
  Could some kind fellow programmer maybe explain what the mistake is, how to guard from possible bugs, or indic<code>enter code here</code>ate the changes i need to do?</p>
  
  <p>The code for the Gridview:</p>
  
  <pre><code>&lt;asp:GridView ID="Foods" runat="server"&gt;
  &lt;Columns&gt;
      &lt;asp:TemplateField&gt;
      &lt;ItemTemplate&gt;
      &lt;asp:CheckBox runat="server" ID="CheckBox1" /&gt;
      &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>and the C# code: (code is under a Button's onclick method)</p>
  
  <pre><code>String output = "";
  foreach (GridViewRow row in Foods.Rows)
  {
  CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
  if ((cb != null) &amp;&amp; (cb.Checked = true))
  {
  output += row.Cells[1].Text.ToString() + ",";
  }
  }
  TextBox1.Text = output;
  </code></pre>
  
  <p>Any help will be appreciated! </p>