Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8687619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:09:44+00:00 2026-06-12T23:09:44+00:00

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

  • 0

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();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:09:46+00:00Added an answer on June 12, 2026 at 11:09 pm
     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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can we pass a grid cell's value to datetimepicker ? I have a
I store some data as XML and the changes of the user as diff
I store some data in MySQL and want to filter out rows that match
I have a wcf service in front of an AzMan store that passes roles
I have a Devexpress Gridview that is linked to a delete, fetch and update
I store data in dictionary, where key is an integer, and value is a
I have a winform which has a gridview that is populating through a stored
store value of input type=hidden into a php variable. The value is set by
I have a problem. I use extjs grid . This grid will be refreshed
I'm trying to select some fields from my database and store them as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.