Link Button in Gridview Template Column

I have a template column in a web form that has a link button in it.  when I click on the link button I want to read the value from the third column for the current row. The following code works fine in a command column of the grid but not from the template column:

 Dim x As String = Me.GridView1.Rows(Me.GridView1.SelectedRow.RowIndex).Cells(3).Text
If I use this in the template column it returns an error.

What am I doing wrong?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Monica PSoftware DeveloperCommented:

Make use of below code., if it meet ur need

<asp:LinkButton ID="lnkview" runat="server" OnClick="lnkview_Click">Delete User</asp:LinkButton>

Open in new window

protected void lnkview_Click(object sender, EventArgs e)

LinkButton lnkbtn= sender as LinkButton;
//getting particular row linkbutton

GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;

//getting userid of particular row
int userid = Convert.ToInt32(gvrecords.DataKeys[gvrow.RowIndex].Value.ToString());
string username = gvrow.Cells[0].Text;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
say if your third column contains a label which displays your desired value, then

Dim x As String =CType(GridView1.SelectedRow.FindControl("YourLabel"), Label).Text
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.