select listbox item if it exist in database
The following code would select/deselect a listbox item, depending if the item is found in the database or not.
On the DataBound event of the listbox, insert the following code:
For i = 0 To myListBox.Items.Count - 1
myitem = myListBox.Items(i).Value
command = New Data.SqlClient.SqlCommand("SELECT * FROM MY_TABLE WHERE MY_PK = '" & myitem & "'", myconnection)
reader = command.ExecuteReader()
If reader.Read() Then
myListBox.Items(i).Selected = True
Else
myListBox.Items(i).Selected = False
End If
reader.Close()
Next