Solved

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

Posted on 2008-06-24
4
461 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

21 Experts available now in Live!

Get 1:1 Help Now