Get Selected Item with Gridview in ASP.NET

I was having a problem before to get selected item with grid view when you click edit button. After spending sometime researching on the internet. I found that we can get the item that you selected by using DataKeynames


  Protected Sub gvPlayerSearch_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvPlayerSearch.RowCommand

            If (e.CommandName = "ViewResult") Then
               //casting the object to gridview
                Dim gv As GridView = DirectCast(sender, GridView)

                Dim objEventResults As  MembersDatasetTableAdapters.EventsResultByMemberIDTableAdapter = _
                                        New   MembersDatasetTableAdapters.EventsResultByMemberIDTableAdapter()

   //get the selected ID
   Dim dtEventResults As MembersDataset.EventsResultByMemberIDDataTable = _

   gvPlayerListEvent.DataSource = dtEventResults
  End If
End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s