Solved

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

Posted on 2008-06-24
4
444 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now