Code for button:
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim li1 As ListItem
Dim addList As New List(Of ListItem)
If (ListBox1.SelectedIndex < 0) Then 'No user selected
MsgBox("Please select a user to add from the Listbox on the left.", vbCritical, "ListBox2 Validation Error")
Else
For Each li1 In ListBox1.Items
If li1.Selected = True Then
adduser(li1.Selected.ToString, intKL)
End If
Next
End If
End Sub
Items are cleared and added using:
ListBox2.Items.Clear()
and
While SQLdr.Read()
If SQLdr.Item(0).ToString <> "" And SQLdr.Item(1).ToString <> "" Then
ListBox2.Items.Add(SQLdr.Item(1).ToString & " - " & SQLdr.Item(0).ToString)
End If
End While
Updates are happening on the load of a dropdownbox
This has something to do with autopostbacks and the page load I think, can someone please help
When I click the add button even if I have selected an item in the listbox, it will always return an error message. I don’t think the listbox changedselected item is firing.
Thanks kolin, your comment really helped.
The problem was that I was populating the listbox on
dropbox1_loadsubroutine and hence everytime a postback was made the listbox would repopulate and no selection could every be made. SelectedItem would revert to -1.