I have a simple ASPX page with a listbox and a button. Listbox has about 8-10 items in it. After the user selects an item (listbox is multi-select) and clicks the button, I'm iterating through the items to get the selected one like so:
For Each Item As ListItem In lstLetters.Items
If Item.Selected Then
Dim LetterID As String
LetterID = Item.Value
LetterIDs.Add(LetterID)
End If
Next
When I step through the code, I select the first item from the listbox. I setup a watch on the 'Item' variable. The code will iterate through each of the items -- but Item.Selected always reads 'False'.
I double-check the page, and sure enough my item is selected on the form.
What the heck is going on?
Thanks in advance,
Jason
Is it possible that maybe you're re-binding the listbox on each postback? That's a common error. Just make sure that you populate the control only if IsPostBack is false. Your code seems OK otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With