how to find datakeys in oncheckedchanged event?
<pre><code>                &lt;asp:Panel ID="pnlFocusAreaPanel" runat="server" GroupingText="Focus Area" Width="800"&gt;
                &lt;table cellspacing="0" cellpadding="0" width="750"&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;asp:GridView ID="dgFocusAreaDetails" runat="server" Width="100%" CssClass="dgStyle"
                                AutoGenerateColumns="False" BorderColor="Silver" BorderWidth="1px" CellPadding="0"
                                ShowHeader="False" OnSelectedIndexChanged="dgFocusAreaDetails_SelectedIndexChanged"
                                DataKeyNames="PK_ID"&gt;
                                &lt;FooterStyle Font-Underline="True" HorizontalAlign="Center" VerticalAlign="Middle"&gt;
                                &lt;/FooterStyle&gt;
                                &lt;Columns&gt;
                                    &lt;asp:TemplateField HeaderText="Focus Area" HeaderStyle-BackColor="Silver"&gt;
                                        &lt;ItemStyle Width="90%" /&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label runat="server" ID="lblFocusArea" Text='&lt;%# DataBinder.Eval(Container.DataItem, "FOCUS_AREA_NAME").ToString()%&gt;'&gt;
                                            &lt;/asp:Label&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Is Current Valid" HeaderStyle-BackColor="Silver"&gt;
                                        &lt;ItemStyle Width="10%" HorizontalAlign="Center" /&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:CheckBox ID="chkFocusArea" runat="server" OnCheckedChanged="OnCheckChangedEvent"
                                                AutoPostBack="true" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                &lt;/Columns&gt;
                            &lt;/asp:GridView&gt;                              
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td align="left"&gt;
                            &lt;asp:TextBox ID="txtFocusArea" runat="server" Width="300px" CausesValidation="true" CssClass="txtStyle" ValidationGroup="focusArea"&gt;
                            &lt;/asp:TextBox&gt;
                            &lt;cc1:TextBoxWatermarkExtender ID="txtFocusAreaWaterMark" runat="server" TargetControlID="txtFocusArea"
                                WatermarkText="Add Focus Area" WatermarkCssClass="WaterMarkStyle"&gt;
                            &lt;/cc1:TextBoxWatermarkExtender&gt;
                            &lt;asp:Button ID="btnAddFocusArea" runat="server" Text="AddFocusArea" CssClass="btnStyle"
                                OnClick="btnAddFocusArea_Click" CausesValidation="true" ValidationGroup="focusArea" /&gt;
                            &lt;asp:RequiredFieldValidator ID="reqtxtFocusArea" runat="server" ControlToValidate="txtFocusArea"
                                 ErrorMessage="Please enter focus area"  Display="Dynamic" ValidationGroup="focusArea"&gt;
                            &lt;/asp:RequiredFieldValidator&gt;
                            &lt;asp:RegularExpressionValidator ID="regexFocusArea" runat="server" ErrorMessage="Invalid characters(&lt;,&gt;,#)"
                                ControlToValidate="txtFocusArea" ValidationExpression="^([^&amp;lt;#&amp;gt;]*)$" ValidationGroup="focusArea"
                                Display="Dynamic" SetFocusOnError="true"&gt;
                            &lt;/asp:RegularExpressionValidator&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
            &lt;/asp:Panel&gt;
</code></pre>

<p>and in code behind</p>

<pre><code>        protected void btnAddFocusArea_Click(object sender, EventArgs e)
    {
        string strFocusArea = txtFocusArea.Text;
        OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);
        if (strFocusArea == string.Empty || strFocusArea == txtFocusAreaWaterMark.WatermarkText)
        {
            lblError.Text = "Focus area is not entered";
        }
        else
        {
            string insertQuery = "INSERT INTO LK_CODECAT_FOCUS_AREA(FOCUS_AREA_NAME,FK_ADDED_BY,ADDED_ON) "+
                                " VALUES('" + strFocusArea + "', "+Session["UserID"] +", GETDATE())";

            try
            {
                myConnection.Open();
                OleDbCommand myCommandToInsert = new OleDbCommand(insertQuery, myConnection);
                myCommandToInsert.ExecuteNonQuery();
            }
            catch(Exception exc)
            {
                ExceptionLogger.LogException(exc);
            }
            finally
            {
                if (myConnection != null)
                {
                    myConnection.Close();
                }
            }
            PopulateFocusArea();

        }
        txtFocusArea.Text = txtFocusAreaWaterMark.WatermarkText;
    }

    private void PopulateFocusArea()
    {
        OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);

        string selectQuery = "SELECT PK_ID, FOCUS_AREA_NAME, IS_CURRENT_FOCUS FROM LK_CODECAT_FOCUS_AREA LKCFA ORDER BY FOCUS_AREA_NAME";

        if (Session["RoleID"].ToString() == "1" || ((Session["WorkID"].ToString() != "9") ||
                    (Session["WorkID2"].ToString() != "9") ||
                    (Session["WorkID3"].ToString() != "9")))
        {
            try
            {
                myConnection.Open();
                OleDbCommand myCommandFocusArea = new OleDbCommand(selectQuery, myConnection);
                OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommandFocusArea);
                DataSet ds = new DataSet();
                myAdapter.Fill(ds);
                dgFocusAreaDetails.DataSource = ds;
                dgFocusAreaDetails.ShowHeader = true;

                dgFocusAreaDetails.DataBind();

            }
            catch (Exception exc)
            {
                ExceptionLogger.LogException(exc);
            }
            finally
            {
                if (myConnection != null)
                {
                    myConnection.Close();
                }
            }
        }
    }

    protected void dgFocusAreaDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
        string selectedCategory = dgFocusAreaDetails.SelectedRow.Cells[1].Text;
        int index = dgFocusAreaDetails.SelectedIndex;
        lblError.Text = dgFocusAreaDetails.DataKeys[index].Value.ToString();
    }

    public void OnCheckChangedEvent(object sender, EventArgs e)
    {
        CheckBox chk = (CheckBox)sender;
        string chkfocusarea = ((Control)chk).ID;

        //string focusAreaDetails = dgFocusAreaDetails.SelectedRow.Cells[0].Text;
        int index =Convert.ToInt32(dgFocusAreaDetails.SelectedIndex);
        if (chk.Checked)
        {
            string updateQuery = "UPDATE [LK_CODECAT_FOCUS_AREA] SET [IS_CURRENT_FOCUS] = 1 WHERE PK_ID = "
                                    +Convert.ToInt32( dgFocusAreaDetails.DataKeys[index].Value)+" ";
        }
        else
        {
            lblError.Text = "unchecked";
        }
    }
</code></pre>

<p>i want to know how i find the datakeyvalue  on checked event because updateQuery in checked event is generating exception.</p>
