locked
Baffled by ID selection in GridView RRS feed

  • Question

  • User472280583 posted

    I have a gridview that is populating with Provider information, like name and title, and hiding the ID column.  This works fine.  However, I have a filter and that filter actually works also, but I want to go and select say the second person in the filtered list, and it is coming back with the ID of that original list from Row(1).  Here is a quick dirty example:

    ORIGINAL LIST ON LOAD

                 PROVIDERS              (ID-hidden)

    Select  Smith, Joe, MD          1

    Select  Jones, Janet, PCA       2

    Select  Medic, Doctor, MD    3

    Select  Doe, Allison, PCA       4

    FILTERED LIST

    Select  Smith, Joe, MD          1

    Select  Doe, Allison, PC         4

    However, if I select Allison Doe from the filtered list, I get the ID for Janet Jones (2 and not 4).

    Structured, it is a page that has three gridviews: one for providers, then specialties, and finally locations.  I want the end user to be able to select a provider, and then filter specialty and location; select specialty, and then filter provider, locations; or select location and list providers, specialties.

    Thanks for any insight

    Tuesday, August 13, 2019 12:29 PM

Answers

  • User475983607 posted

    I am not even getting the row index,  Here is the code that is "storing" that ID

     Dim selectedRow As GridViewRow = gvProviders.SelectedRow
     SelectedProviderID = gvProviders.SelectedRow.Cells.Item(1).Text

    And when stepping through the code the selectedRow does reflect the proper cells AND Item(1) is the ID of the correct provider, but it is returning the ID of the row of the prior table data.

    I can only assume you are mistaken or there are other issues with the code.  Keep in mind, that we can only see the code you share on the forum.  Post all the relevant code if you need community debugging support.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 13, 2019 1:03 PM

All replies

  • User475983607 posted

    You have logical bugs in your code.  It seems you are using a row index as the record ID.  

    Tuesday, August 13, 2019 12:44 PM
  • User472280583 posted

    I am not even getting the row index,  Here is the code that is "storing" that ID

     Dim selectedRow As GridViewRow = gvProviders.SelectedRow
     SelectedProviderID = gvProviders.SelectedRow.Cells.Item(1).Text

    And when stepping through the code the selectedRow does reflect the proper cells AND Item(1) is the ID of the correct provider, but it is returning the ID of the row of the prior table data.

    Tuesday, August 13, 2019 12:50 PM
  • User475983607 posted

    I am not even getting the row index,  Here is the code that is "storing" that ID

     Dim selectedRow As GridViewRow = gvProviders.SelectedRow
     SelectedProviderID = gvProviders.SelectedRow.Cells.Item(1).Text

    And when stepping through the code the selectedRow does reflect the proper cells AND Item(1) is the ID of the correct provider, but it is returning the ID of the row of the prior table data.

    I can only assume you are mistaken or there are other issues with the code.  Keep in mind, that we can only see the code you share on the forum.  Post all the relevant code if you need community debugging support.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 13, 2019 1:03 PM
  • User472280583 posted

    Thanks for the response.  When you mentioned logic error, it made me step through the code (F8), step by step and I found that I forgot the statement in Form_Load If Not IsPostBack, so it kept running the original form load list on a button click or a select link.  However, once I put this in, it is functioning as to be expected.

    Tuesday, August 13, 2019 1:56 PM