title: How to add event for Checkbox click in Asp.net Gridview Column
body: <p>I have a gridview in asp where i have added first column as checkbox column.Now i want to select this column and get the id values of the row ..But I am not getting how to do it..</p>
  
  <p>This is my Aspx code..</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
                      AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" 
                      BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" 
                      GridLines="None"&gt;
                      &lt;AlternatingRowStyle BackColor="PaleGoldenrod" /&gt;
                      &lt;Columns&gt;
                       &lt;asp:TemplateField&gt;
                              &lt;HeaderTemplate&gt;
                                  &lt;asp:CheckBox ID="chkhdr" runat="server" /&gt;
                              &lt;/HeaderTemplate&gt;
                            &lt;ItemTemplate&gt;
                                  &lt;asp:CheckBox ID="chkChild" runat="server" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="Username"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("col0") %&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="Role(Admin)"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:CheckBox ID="chkAdmin" runat="server" Checked='&lt;%# Eval("col1") %&gt;' /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="Role(User)"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:CheckBox ID="chkUser" runat="server" Checked='&lt;%# Eval("col2") %&gt;' /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="Role(GeneralUser)"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:CheckBox ID="chkgen" runat="server" Checked='&lt;%# Eval("col3") %&gt;' /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
                  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>And here is my code behind file...</p>
  
  <pre><code>protected void BindGridviewData()
  {
  
      var role = from MembershipUser u in Membership.GetAllUsers()
                  select new
                  {
                      User = u.UserName,
                      Role = string.Join(",", Roles.GetRolesForUser(u.UserName))
                  };
  
      DataTable dTable = new DataTable();
      dTable.Columns.Add("col0", typeof(string));
      dTable.Columns.Add("col1", typeof(bool));
      dTable.Columns.Add("col2", typeof(bool));
      dTable.Columns.Add("col3", typeof(bool));
      foreach (MembershipUser u in Membership.GetAllUsers())
      {
          DataRow dRow = dTable.NewRow();
          dRow[0] = u.UserName;
  
          string[] roles = Roles.GetRolesForUser(u.UserName);
          dRow[1] = roles.Contains("Admin") ? true : false;
          dRow[2] = roles.Contains("DPAO User") ? true : false;
          dRow[3] = roles.Contains("GeneralUser") ? true : false;
          dTable.Rows.Add(dRow);
      }
      GridView1.DataSource = dTable;
      GridView1.DataBind();
  }
  </code></pre>
  
  <p>Please Guys help me as i have no idea how to accomplish this ...Thanks in advance...</p>