title: Bind and access checkbox value within a gridview
body: <p>In my grid view I've a checkbox column, and am binding the gridview with a dictionary. I need to get the corresponding <code>Id</code> from the checked boxes.</p>
  
  <p>In my dictionary I've the key values like</p>
  
  <pre><code>Id         Name
  --         ----
   1         Arts
   2         Science
   3         Engineering
  </code></pre>
  
  <p>Here, I tried to bind the value for this checkbox as</p>
  
  <pre><code>&lt;asp:TemplateField&gt;
      &lt;ItemTemplate&gt;
        &lt;asp:CheckBox ID="chkSelItem" value="&lt;%# Eval("Key.Id") %&gt;" 
                                                         runat="server" /&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  
  &lt;asp:TemplateField HeaderText="Department"&gt;
      &lt;ItemTemplate&gt;
           &lt;%# Eval("Key.Name") %&gt;
      &lt;/ItemTemplate&gt;
      &lt;HeaderStyle HorizontalAlign="Left" /&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>and from the codebehind, I tried like</p>
  
  <pre><code>foreach (GridViewRow row in gridDepartments.Rows)
          {
              CheckBox chkSelItem = (CheckBox)row.FindControl("chkSelItem");
  
              if (chkSelItem.Checked)
              {
                  int departmentId = int.Parse(chkSelItem.Text);
                  ////
                  ////                 
              }
          }
  </code></pre>
  
  <p>its throwing error, or not showing any value for the checkbox.</p>
  
  <p>I also trid with <code>FindControl</code>, but no use of it, coz in the <code>key &amp; Value</code> pair am using a class(which inherits another class) and a bool. thats what am trying like this, can anyone help me here, thanks in advance.....</p>