title: iterate through ALL rows in a GridView
body: <pre><code> &lt;asp:TemplateField HeaderText="Select"&gt;
   &lt;ItemTemplate&gt;
   &lt;asp:CheckBox ID="chkSelected" runat="server" Checked="false"&gt;&lt;/asp:CheckBox&gt;
    &lt;/ItemTemplate&gt;
   &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>elow code works fine but there is a bug :</p>
  
  <p>if Employee object has return 5 rows and i am trying to checked the check box based on the ids but instead its just matching only the last id - it suppose to checked all 5 rows..</p>
  
  <pre><code>List&lt;Employee&gt; result = new List&lt;Employee&gt;();
  long Id = (long)Session["Id"];
  result = Employee.GetEmployeeById(Id);
  
  foreach (GridViewRow row in gv.Rows)
  {
     CheckBox chkBox = row.FindControl("chkSelected") as CheckBox;
     if (c != null)
     {
        if (result.Count &gt; 0)
        {
            foreach (Employee item in result)
            {
               Label Id = row.FindControl("lblId") as Label;
               if (Id.Text == item.Id.ToString())
               {
                   chkBox.Checked = true;
               }
               else
               {
                  chkBox.Checked = false;
               }
             }
         }
  </code></pre>