Forum Moderators: open
I am trying to pull data from sql which populates the first listbox with a list of all pages on the website.
The second box is where we would like to add or remove the pages that users can edit. This will be populated from a table. But the goal is to have the ability to select multiple items in the first box and click the add button to move those items to the second list box. Also I would like to select items from the second listbox and click the remove button and this removes the items from this box.
The code below is what I am using which comes from: [123aspx.com ] The error message is below as well.
Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim strSelection As String
If Not allRoles.SelectedItem Is "" Then
strSelection = allRoles.SelectedItem.Text
If allRoles.Items.FindByText(strSelection) Is "" Then
EditableRoles.Items.Add(strSelection)
EditableRoles.SelectedIndex = 0
allRoles.Items.Remove(strSelection)
End If
End If
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
Dim strSelection As String
If Not EditableRoles.SelectedItem Is "" Then
strSelection = EditableRoles.SelectedItem.Text
If EditableRoles.Items.FindByText(strSelection) Is "" Then
allRoles.Items.Add(strSelection)
allRoles.SelectedIndex = 0
EditableRoles.Items.Remove(strSelection)
End If
End If
End Sub
Error Message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 231: If Not allRoles.SelectedItem Is "" Then
Line 232:
Line 233: strSelection = allRoles.SelectedItem.Text
Line 234:
Line 235: If allRoles.Items.FindByText(strSelection) Is "" Then
Thank you for your help.