Web Form Listbox SelectedIndex Preservation

  • Thread starter Thread starter fripper
  • Start date Start date
F

fripper

When I have a populated list box in a web form in VB under VS .Net 2003 and
then select an item by clicking it and then click a button to perform some
function based on the selected item I find that the selectedindex property
of the list box control is -1 ... indicating no item is selected ... and yet
one IS selected. I suspect this has something to do with page postbacks
but I would appreciate a explanation of what is happening here. Can I not
select and item and then preserve that selectedindex property across a click
of a button control?

Thanks very much.
 
Fripper,

How did you fill that listbox, I tried it and had not any problem with what
you wrote.

I hope this helps,

Cor
 
Cor:

Problem solved ... thanks in large part to your question about how the list
box was filled. The code to populate the list box was in the load event
handler ... it first clears the list box and then loads it up. I had to
move that out of the load event handler and into the button click event
handler. I don't have a good handle on when pages are reloaded in .Net.

Thanks for your response.
 
Back
Top