Use
RowCommand
Event for that.
Eg in .aspx page:
<asp:templatefield headertext="Link" xmlns:asp="#unknown">
<itemtemplate>
<asp:linkbutton id="LinkButton1" runat="server">
CommandName ="Link">LinkButton</asp:linkbutton>
</itemtemplate>
</asp:templatefield>
In .CS page:C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Link")
{
LinkButton img = (LinkButton)e.CommandSource as LinkButton;
GridViewRow row = img.NamingContainer as GridViewRow;
Label lbid = (Label)row.FindControl("label1");
int id = Convert.ToInt32(lbid.Text);
}
}
VB:
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
If e.CommandName = "Link" Then
Dim img As LinkButton = TryCast(DirectCast(e.CommandSource, LinkButton), LinkButton)
Dim row As GridViewRow = TryCast(img.NamingContainer, GridViewRow)
Dim lbid As Label = DirectCast(row.FindControl("label1"), Label)
Dim id As Integer = Convert.ToInt32(lbid.Text)
End If
End Sub