[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 856
  • Last Modified:

Get Value of DataGrid Using LinkButton C#

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?
  • 2
1 Solution
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

OteroJCAuthor Commented:
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now