Get the ID of a record in a gridview asp.net
<p>i have a checkbox in a template field of a gridview and i want to get the id of the record at a checkbox tick. how do i do it? i am doing asp.net and  also by using datakeynames instead, my gridview also shows the datakeynames persID column. why? </p>

<p>my code: </p>

<pre><code>&lt;asp:GridView ID="GridViewHostelMember" runat="server" DataKeyNames="_PersID" AutoGenerateColumns="false"&gt;
    &lt;Columns&gt;
        &lt;asp:BoundField DataField="_PersID" HeaderText="_PersID" /&gt;
        &lt;asp:BoundField DataField="FirstName" HeaderText="First Name" /&gt;
        &lt;asp:BoundField DataField="LastName" HeaderText="LastName" /&gt;
        &lt;asp:BoundField DataField="DOB" HeaderText="DOB" /&gt;
        &lt;asp:BoundField DataField="FatherName" HeaderText="FatherName" /&gt;
        &lt;asp:BoundField DataField="Type" HeaderText="Type" /&gt;
        &lt;asp:TemplateField&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:CheckBox ID="CheckBoxSelect" runat="server" /&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;


protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridViewRow item in this.GridViewHostelMember.Rows)
    {
        CheckBox chbTemp = item.FindControl("CheckBoxSelect") as CheckBox;
        if (chbTemp != null)
        {
            if (chbTemp.Checked)
            {
                Label1.Text = item.Cells[0].Text;
            }
        }
    }
}
</code></pre>
