title: asp.net vb.net gridview, get row id when pressing template field button
body: <p>I have a template field with a button. I want to press the button and get the row Id so I can return the users selection. I have a regular select button which works fine but the user want the people who are not employee’s to hide the select button. I have this working but since it’s a template field it fires the RoW_command procedure and I cannot seem to get the row index since it is a template field and not the regular Select button. Or I cannot seem to name the Regular select button since it Command field does not have a Name or ID property?</p>
  
  <p>Like I said this works hiding the template field called btnSelect
    Private Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound</p>
  
  <pre><code>    If e.Row.RowType = DataControlRowType.DataRow Then
  
          If (DataBinder.Eval(e.Row.DataItem, "LegacyPersonType") &lt;&gt; "Employee") Then
              e.Row.ForeColor = Drawing.Color.Black
              e.Row.BackColor = Drawing.Color.Yellow ' This will make row back color yellow 
              e.Row.FindControl("btnSelect").Visible = False
  
          Else
              e.Row.ForeColor = Drawing.Color.Black
              e.Row.BackColor = Drawing.Color.White   ' the normal employees make white
          End If
  
      End If
  
  End Sub
  </code></pre>
  
  <p>I need to find the Row index  when I press btnSelect<br>
  Private Sub GridView3_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView3.RowCommand</p>
  
  <pre><code>    Dim index As Integer = Convert.ToInt32(e.CommandArgument) ‘ Error invalid 
  </code></pre>
  
  <p>‘ in other words when pressing the tem-plate field there is no e.CommandArgument 
  ‘But clicking the regular select there is </p>
  
  <pre><code>    Dim row As GridViewRow = GridView3.Rows(index)
      Session("EnterpriseID") = HttpUtility.HtmlDecode(GridView3.Rows(index).Cells(2).Text)
      Dim EmployeeType As String = HttpUtility.HtmlDecode(GridView3.Rows(index).Cells(7).Text)
      Dim CommonName As String = HttpUtility.HtmlDecode(GridView3.Rows(index).Cells(1).Text)
  
      Dim EnterpriseID = HttpUtility.HtmlDecode(GridView3.Rows(index).Cells(6).Text)
  </code></pre>