Toot
February 28th, 2005, 09:05 AM
Hi gurus, just starting out on ASP.NET so excuse my obvious lack of experience...
How do I know what item is selected in a listbox on an ASP.NET web form? I've tried attaching to the SelectedIndexChanged event. First time around, it was being called when the user submitted the form and the listbox's SelectedIndex value was always -1 so I tried changing the Autopost property on the form to true which now means that the event occurs when the index is changed ... but SelectedIndex is still always -1. So I've tried to add a piece of client code which captures the OnSelectedItemChanged event and sets another hidden input on the form so that the server can pick it up. But now I can't work out how to get at that value from the server code.
Clearly I'm missing something pretty basic - please put me out of my misery!
Can someone provide a sample page that contains a listbox and a submit button that will show which item was selected in the listbox?
PS: I'm writing in C# but I won't be picky about sample code :) .
Thanks very much, you're great.
T
How do I know what item is selected in a listbox on an ASP.NET web form? I've tried attaching to the SelectedIndexChanged event. First time around, it was being called when the user submitted the form and the listbox's SelectedIndex value was always -1 so I tried changing the Autopost property on the form to true which now means that the event occurs when the index is changed ... but SelectedIndex is still always -1. So I've tried to add a piece of client code which captures the OnSelectedItemChanged event and sets another hidden input on the form so that the server can pick it up. But now I can't work out how to get at that value from the server code.
Clearly I'm missing something pretty basic - please put me out of my misery!
Can someone provide a sample page that contains a listbox and a submit button that will show which item was selected in the listbox?
PS: I'm writing in C# but I won't be picky about sample code :) .
Thanks very much, you're great.
T