Q:

How to Store SelectedRow.Cell[0] value in a session when CommandField is "Select" in a GridView

How to Store SelectedRow.Cell[0] value in a session when CommandField is "Select" in a GridView. ? What the changes i will do in my code so that when a Select Command executes on my grid (By Clicking on Select Link of my grid), It will Store the NatureOfWorkID of that row in the session variable. Below is my code. Please guide me that what changes required in the below code so that when ever some one will click on Select, the natureofworkID of that row will be stored in a Session and i will bind another grid from the session variable as per my requirement.
 <asp:GridView ID="GVNatureOFWork" runat="server" AllowPaging="true" ShowFooter="true" PageSize="10" AutoGenerateColumns="false"
    DataKeyNames="NatureOfWorkID"
     OnPageIndexChanging="GVNatureOFWork_PageIndexChanging" 
     onrowcancelingedit="GVNatureOFWork_RowCancelingEdit" 
     onrowcommand="GVNatureOFWork_RowCommand" onrowdeleting="GVNatureOFWork_RowDeleting" 
     onrowediting="GVNatureOFWork_RowEditing" onrowupdating="GVNatureOFWork_RowUpdating" 
     OnSelectedIndexChanged="GVNatureOFWork_SelectedIndexChanged" OnRowDataBound="GVNatureOFWork_RowDataBound"
     HeaderStyle-BackColor="BlueViolet" 
     HeaderStyle-ForeColor="White" BackColor="White">
        <Columns>
            <asp:TemplateField HeaderText="NatureOfWorkID">
                <ItemTemplate>
                    <asp:Label ID="lblNautureOfWorkID" runat="server" Text='<%#Eval("NatureOfWorkID") %>' />
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Nature of Work Name">
                <ItemTemplate>
                    <asp:Label ID="lblNatureOfWorkName" runat="server" Text='<%#Eval("NatureOfWorkName") %>' />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtNatureOfWorkName" runat="server" Text='<%#Eval("NatureOfWorkName") %>' />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtAddNatureOfWorkName" runat="server"  />
                </FooterTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Enable/Disable">
                <ItemTemplate>
                    <asp:Label ID="lblNOWStatus" runat="server" Text='<%# (int)Eval("IsNOWEnabled") == 1 ? "Enabled" : "Disabled" %>' />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:RadioButtonList ID="radiolistStatus" runat="server">
                    <asp:ListItem Text="Enable" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Disable" Value="0"></asp:ListItem>
                    </asp:RadioButtonList>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:RadioButtonList ID="radiolistStatusAdd" runat="server">
                    <asp:ListItem Text="Enable" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Disable" Value="0"></asp:ListItem>
                    </asp:RadioButtonList>
                </FooterTemplate>
                </asp:TemplateField>

            <asp:TemplateField  ShowHeader="False" > 
                <EditItemTemplate> 
                  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
                  <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
                </EditItemTemplate> 
                <FooterTemplate> 
                  <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton> 
                </FooterTemplate> 
                <ItemTemplate> 
                  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
                </ItemTemplate> 
            </asp:TemplateField> 
            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True"  ShowHeader="True" /> 
            <asp:CommandField ShowSelectButton="True" ItemStyle-CssClass="HiddenColumn" HeaderStyle-CssClass="HiddenColumn"/> 
      </Columns>
  </asp:GridView><br /><br /><br /><br />

<asp:GridView ID="GVRegionProject" runat="server" AllowPaging="true" ShowFooter="true" PageSize="10" AutoGenerateColumns="false"
     OnPageIndexChanging="GVRegionProject_PageIndexChanging" 
     onrowcancelingedit="GVRegionProject_RowCancelingEdit" 
     onrowcommand="GVRegionProject_RowCommand" onrowdeleting="GVRegionProject_RowDeleting" 
     onrowediting="GVRegionProject_RowEditing" onrowupdating="GVRegionProject_RowUpdating" 
     OnSelectedIndexChanged="GVRegionProject_SelectedIndexChanged"
     HeaderStyle-BackColor="BlueViolet" 
     HeaderStyle-ForeColor="White" BackColor="White">
     <Columns>
     <asp:TemplateField HeaderText="Region/Project ID">
                <ItemTemplate>
                    <asp:Label ID="lblRegionProjectID" runat="server" Text='<%#Eval("RegionProjectID") %>' />
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Region/Project Name">
                <ItemTemplate>
                    <asp:Label ID="lblRegionProjectName" runat="server" Text='<%#Eval("RegionProjectName") %>' />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtRegionProjectName" runat="server" Text='<%#Eval("RegionProjectName") %>' />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtAddRegionProjectName" runat="server"  />
                </FooterTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Enable/Disable">
                <ItemTemplate>
                    <asp:Label ID="lblRPStatus" runat="server" Text='<%# (int)Eval("IsRegionProjectEnabled") == 1 ? "Enabled" : "Disabled" %>' />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:RadioButtonList ID="radiolistStatus" runat="server">
                    <asp:ListItem Text="Enable" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Disable" Value="0"></asp:ListItem>
                    </asp:RadioButtonList>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:RadioButtonList ID="radiolistStatusAdd" runat="server">
                    <asp:ListItem Text="Enable" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Disable" Value="0"></asp:ListItem>
                    </asp:RadioButtonList>
                </FooterTemplate>
                </asp:TemplateField>

            <asp:TemplateField  ShowHeader="False" > 
                <EditItemTemplate> 
                  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
                  <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
                </EditItemTemplate> 
                <FooterTemplate> 
                  <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton> 
                </FooterTemplate> 
                <ItemTemplate> 
                  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
                </ItemTemplate> 
            </asp:TemplateField> 
            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True"  ShowHeader="True" /> 
            <asp:CommandField HeaderText="County" ShowHeader="false" ShowSelectButton="True"/>

 </Columns>
 </asp:GridView>

Code Behind is :-
        private void BindGrid()
    {
        dataTable = new DataTable();
        cmd.Connection = conn;
        cmd.CommandText = "SELECT * FROM natureOfWork";
        ad = new SqlDataAdapter(cmd);
        ad.Fill(dataTable);
        GVNatureOFWork.DataSource = dataTable;
        GVNatureOFWork.DataBind();
    }

    protected void GVNatureOFWork_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GVNatureOFWork.PageIndex = e.NewPageIndex;
        BindGrid();
    }

    protected void GVNatureOFWork_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GVNatureOFWork.EditIndex = -1;
        BindGrid();

    }

    protected void GVNatureOFWork_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("AddNew"))
        {

            TextBox txtAddNatureOfWorkName = (TextBox)GVNatureOFWork.FooterRow.FindControl("txtAddNatureOfWorkName");
            RadioButtonList radiolistStatusAdd = (RadioButtonList)GVNatureOFWork.FooterRow.FindControl("radiolistStatusAdd");
            if ((txtAddNatureOfWorkName.Text != "")&&(radiolistStatusAdd.SelectedValue != string.Empty))
             {
                cmd.Connection = conn;
                cmd.CommandText = "INSERT INTO NatureOFWork(NatureOFWorkname, isNOWEnabled ) Values('" + txtAddNatureOfWorkName.Text + "', '" + radiolistStatusAdd.SelectedValue.ToString() + "')";
                conn.Open();
                cmd.ExecuteNonQuery();
            }
            BindGrid();
            conn.Close();
        }

        if (e.CommandName.Equals("Select"))
        {

        }
    }

    protected void GVNatureOFWork_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblNautureOfWorkID = (Label)GVNatureOFWork.Rows[e.RowIndex].FindControl("lblNautureOfWorkID");
        cmd.Connection = conn;
        cmd.CommandText = "DELETE FROM NatureOFWork WHERE NatureOfWorkID='" + lblNautureOfWorkID.Text.ToString() + "'";
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        BindGrid();
    }

    protected void GVNatureOFWork_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GVNatureOFWork.EditIndex = e.NewEditIndex;            
        BindGrid();

    }

    protected void GVNatureOFWork_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        Label lblNautureOfWorkID = (Label)GVNatureOFWork.Rows[e.RowIndex].FindControl("lblNautureOfWorkID");
        TextBox txtNatureOfWorkName = (TextBox)GVNatureOFWork.Rows[e.RowIndex].FindControl("txtNatureOfWorkName");
        RadioButtonList radiolistStatus = (RadioButtonList)GVNatureOFWork.Rows[e.RowIndex].FindControl("radiolistStatus");
        string isenabled = radiolistStatus.SelectedValue.ToString();
        cmd.Connection = conn;
        cmd.CommandText = "UPDATE NatureOfWork SET NatureOfWorkname ='" + txtNatureOfWorkName.Text + "',IsNowEnabled=" + isenabled.ToString() + "  WHERE NatureOFWorkID=" + lblNautureOfWorkID.Text.ToString();
        conn.Open();
        cmd.ExecuteNonQuery();
        GVNatureOFWork.EditIndex = -1;
        BindGrid();
        conn.Close();
    }

    protected void GVNatureOFWork_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblNautureOfWorkID = (Label)e.Row.FindControl("lblNautureOfWorkID");
            Label lblNatureOfWorkName = (Label)e.Row.FindControl("lblNatureOfWorkName");
            TextBox txtNatureOfWorkName = (TextBox)e.Row.FindControl("txtNatureOfWorkName");
            TextBox txtAddNatureOfWorkName = (TextBox)e.Row.FindControl("txtAddNatureOfWorkName");
            RadioButtonList radiolistStatusAdd = (RadioButtonList)e.Row.FindControl("radiolistStatusAdd");
            RadioButtonList radiolistStatus = (RadioButtonList)e.Row.FindControl("radiolistStatus");
            Label lblNOWStatus = (Label)e.Row.FindControl("lblNOWStatus");

        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
        }
    }

    protected void GVNatureOFWork_SelectedIndexChanged(object sender, EventArgs e)
    {
        string natureOfWorkID=GVNatureOFWork.SelectedRow.Cells[0].Text;
        BindRegionProjectInfoGrid();
    }

A:

 protected void GVNatureOFWork_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = GVNatureOFWork.SelectedIndex;
        string natureofwrkid = GVNatureOFWork.DataKeys[index].Value.ToString();
        Session["NOWID"] = natureofwrkid;
        lblDisplayNOWID.Text = natureofwrkid;
        BindRegionProjectInfoGrid();

    }

By adding these lines, Now i am able to get Cell[0] value of the selected row in my grid. Thanks To every one for guiding me to get the solution.

