Link to home
Start Free TrialLog in
Avatar of htabbach
htabbachFlag for United States of America

asked on

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?
Avatar of Chumad
Chumad

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 :)
Avatar of htabbach

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Chumad
Chumad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?