• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

SelectedIndex always returning -1 for a ListView (ASP.NET 3.5 and VB.NET)

Hello,

I have a listView with a select button, when I click on the select button the SelectedIndexChanged fires up but when I do ;

Dim i as integer
i = lvOffers.selectedIndex it always returns -1

any ideas why?
0
htabbach
Asked:
htabbach
  • 2
  • 2
1 Solution
 
ChumadCommented:
Do you populate the listView in the page_load event? If so, you are probably losing the selection. In most cases, you only need to re-load the listView when page.IsPostback = false..

hope this helps :)
0
 
htabbachAuthor Commented:
No, I populate the list from OnSelectedIndexChanged event of a DataGrid control, so it only populates if the user click on the select button of the DataGrid
0
 
ChumadCommented:
My guess is that it's still being reset or re-populated somehow. If you put a break point into the very first line of your page_load event and check what SelectedIndex is (when it breaks after clicking the select button), do you still see -1 or does it have a value?
0
 
htabbachAuthor Commented:
I debuged the app and it only populates once and still returns -1. Do I have to have a selectedItemtemplate for it to return the selectedindex?
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now