Solved

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

Posted on 2008-06-24
4
470 Views
Last Modified: 2013-11-26
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
Comment
Question by:htabbach
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Chumad
ID: 21858143
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
 

Author Comment

by:htabbach
ID: 21858182
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
 
LVL 8

Accepted Solution

by:
Chumad earned 500 total points
ID: 21858222
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
 

Author Comment

by:htabbach
ID: 21858314
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question