Technical Insights: Azure, .NET, Dynamics 365 & EV Charging Architecture

Tag: gridview

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 = _
                                objEventResults.EventsResultByMemberID(gv.DataKeys(0).Value)

   gvPlayerListEvent.DataSource = dtEventResults
   gvPlayerListEvent.DataBind()
  End If
End Sub

How to clear a gridview

Normally, we would like to clear a gridview for various reason. I want the data to be cleared from grid view everytime user does the search and the grid view will be binded again if the user click a particular button otherwise the last result will be displayed when the new dataset/datatable does not return any rows. This is the simplest way i ever think of

gvPlayerListEvent.DataSourceID = String.Empty
gvPlayerListEvent.DataBind()

Powered by WordPress & Theme by Anders Norén