How do I get the text of the selected item in the listbox?

1

My attempt below, is giving object reference, why? how to solve?

    
asked by anonymous 09.06.2015 / 22:39

2 answers

1

Your problem is in Page_Load , because every time a postback is done your Page_Load method is called and is always reloading your data.

To avoid reloading the data in PostBack simply do this:

Protected Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        PreencheListaUsuarios() 
        PreencheListaPerfis()
    End If
End Sub

This way when it reaches btnDeletarPerfil_click the data in the listbox will be normal. :)

    
09.06.2015 / 23:34
0
If (lbPerfis.Items.Count = 0) = False Then
    If (lbPerfis.SelectedItem Is Nothing) = False Then
         roles.DeleteRole(lbPerfis.SelectedItem.Text.ToString)
    End If
End If
    
10.06.2015 / 22:18