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?
htabbachAsked:
Who is Participating?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.