We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Get Value of DataGrid Using LinkButton C#

OteroJC asked
Medium Priority
Last Modified: 2012-06-21
I have a data grid grdSchedule that has a template column in it with a link button. When a user clicks the link button I want to retrieve the value of the fifth column and display it in a a separate control. I'm using Visual Studio 2008 and C#. How do I get the value of the fifth column for the row on which the user has clicked the link button?
Watch Question

Rather than try and find the value from the fifth column, you should add the value of the 5th column to the commandargument property of the link button when binding the data.
<asp:GridView ID="grdSchedule" runat="server">
                    <asp:LinkButton CommandArgument='<%# Eval("ColumnNameFromData") %>' Text="Test" OnClick="LinkButton_Click" runat="server" />
protected void LinkButton_Click(object sender, EventArgs e)
        LinkButton b = (LinkButton)sender;
        string x = b.CommandArgument;

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thank you so much. I was over complicating my solution and succeeding only at giving myself a big giant headache. This is the neatest (cleanest) solution I have seen in all my searching.
No problem
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.