Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Row index for a link button in a grid

Row index for a link button in a grid

Scheduled Pinned Locked Moved ASP.NET
questioncssdatabasedesign
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin_
    wrote on last edited by
    #1

    How can I find the row index when a linkbutton is clicked within a grid?
    Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand e.CommandArgument does not give me the row index. Thanks, Martin

    K 1 Reply Last reply
    0
    • M Martin_

      How can I find the row index when a linkbutton is clicked within a grid?
      Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand e.CommandArgument does not give me the row index. Thanks, Martin

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      Microsoft help suggest setting it in the row create:

      Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

      ' The GridViewCommandEventArgs class does not contain a 
      ' property that indicates which row's command button was
      ' clicked. To identify which row's button was clicked, use 
      ' the button's CommandArgument property by setting it to the 
      ' row's index.
      If e.Row.RowType = DataControlRowType.DataRow Then
      
        ' Retrieve the LinkButton control from the first column.
        Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
            
        ' Set the LinkButton's CommandArgument property with the
        ' row's index.
        addButton.CommandArgument = e.Row.RowIndex.ToString()
        
      End If
      

      End Sub

      Hope that helps Ben

      M 1 Reply Last reply
      0
      • K kubben

        Microsoft help suggest setting it in the row create:

        Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        ' The GridViewCommandEventArgs class does not contain a 
        ' property that indicates which row's command button was
        ' clicked. To identify which row's button was clicked, use 
        ' the button's CommandArgument property by setting it to the 
        ' row's index.
        If e.Row.RowType = DataControlRowType.DataRow Then
        
          ' Retrieve the LinkButton control from the first column.
          Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
              
          ' Set the LinkButton's CommandArgument property with the
          ' row's index.
          addButton.CommandArgument = e.Row.RowIndex.ToString()
          
        End If
        

        End Sub

        Hope that helps Ben

        M Offline
        M Offline
        Martin_
        wrote on last edited by
        #3

        It did. Once again, thank you Ben. :)

        K 1 Reply Last reply
        0
        • M Martin_

          It did. Once again, thank you Ben. :)

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          You are welcome Ben

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups