Hello, I also had this problem of getting row index in template column.
I searched alot on internet but was unable to find a solution. So I
tried by myself and got success in it. Here is the solution.
Basically I work in C# but libraries are same for both C#.net and VB.net
I bind that control in RowDataBound
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType
!= DataControlRowType.Footer && e.Row.RowType !=
DataControlRowType.Pager)
{
LinkButton lblTagLink =new LinkButton();
lblTagLink = (LinkButton)e.Row.FindControl("btnAddTags");
lblTagLink.CommandArgument= e.Row.RowIndex.ToString();
}
}
So got the row index in
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
int RowIndex_ = int.Parse(e.CommandArgument.ToString());
Label lblMediaID_ =
(Label)GridView1.Rows[RowIndex_].FindControl("lblMedia_ID");
}
as I got the row index, I had access of each control in that
row as mentioned above.