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 6103497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:08+00:00 2026-05-23T13:44:08+00:00

I have a gridview which is pulling it data from a stored procedure. In

  • 0

I have a gridview which is pulling it data from a stored procedure. In the column title, I have used a Linkbutton. I would like to grab the Ctl ID and store it in a variable when it is clicked. I am not sure what is happening, but I get a few strings going through. Below is my code and this is similar to my previous post.

ASP.NET

<asp:TemplateField HeaderText="ID">
            <ItemTemplate>
            <asp:LinkButton ID="lnkID" runat="server" OnClick="lblClick1"
            Text='<%#Eval("ID") %>'>
            </asp:LinkButton>
            </ItemTemplate>
            </asp:TemplateField>

C#:

 GridViewRow row = gv2.SelectedRow;
    string controlId = ((LinkButton)row.FindControl("lnkID")).ID;
    lblshow.Text = controlId;

Can someone help me get up and running. Thanks.

  • 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-05-23T13:44:09+00:00Added an answer on May 23, 2026 at 1:44 pm

    You could use a hidden field to store the id:

    <ItemTemplate>
        <asp:HiddenField 
            runat="server" 
            ID="ID" 
            Value='<%# Eval("ID") %>' 
        />
    
        <asp:LinkButton 
            runat="server" 
            OnClick="LabelClick" 
            Text="click me" 
        />
    </ItemTemplate>
    

    and then:

    protected void LabelClick(object sender, EventArgs e)
    {
        var hiddenField = (HiddenField)((Control)sender).FindControl("ID");
        var id = hiddenField.Value;
        // Do something with the id        
    }
    

    UPDATE:

    Full working example:

    <%@ Page Language="C#" %>
    <script type="text/c#" runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grid.DataSource = Enumerable.Range(1, 10).Select(x => new
                {
                    ID = x
                });
                grid.DataBind();
            }
        }
    
        protected void LabelClick(object sender, EventArgs e)
        {
            var hiddenField = (HiddenField)((Control)sender).FindControl("ID");
            result.Text = string.Format("selected id: {0}", hiddenField.Value);
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <asp:GridView ID="grid" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:TemplateField HeaderText="ID">
                    <ItemTemplate>
                        <asp:HiddenField 
                            runat="server" 
                            ID="ID" 
                            Value='<%#Eval("ID") %>' 
                        />
                        <asp:LinkButton 
                            runat="server" 
                            OnClick="LabelClick" 
                            Text="click me" 
                        />
                    </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    
            <asp:Label ID="result" runat="server" />
        </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this itemtemplate for a gridview column that is pulling data from a
I have a GridView which binds data from DB, and using rowboundevent, I want
I have a gridview which uses a stored procedure with session[UserName] as a parameter
I have an ASP.NET GridView which has columns that look like this: | Foo
I have a GridView which supports deleting. I'd like to add a pop up
I have a gridview which in one column is displaying MAC addresses. Instead of
I have a gridview which successfully binds to the database and gets all data.
I have a gridview which can be filtered from one or more values in
I have a GridView which is showing some data: Entity_ID (PK) Name Description Now
I have a GridView which is showing results and from which I am deleting

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.