codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Ruoli.aspx.vb" Inherits="Amministratore_Ruoli" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Gestione dei ruoli</title>
<link href="Stile/stile.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
Ruoli definiti:
<asp:ListBox ID="lstRuoli" runat="server">
</asp:ListBox>
<asp:Button ID="btnCancellaRuolo" runat="server" Text="Elimina" />
Aggiungi nuovo ruolo
Nome: <asp:TextBox ID="txtNuovoRuolo" runat="server" />
<asp:Button ID="btnNuovoRuolo" runat="server" Text="Aggiungi" />
</div>
<asp:Label ID="lblMessaggio" runat="server" />
</form>
</body>
</html>
questa è la pagina Ruoli.aspx
e questa la pagina Ruoli.aspx.vb
codice:
Partial Class Amministratore_Ruoli
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Aggiorna()
End Sub
Sub Aggiorna()
lstRuoli.DataSource = Roles.GetAllRoles()
lstRuoli.DataBind()
End Sub
Protected Sub btnNuovoRuolo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNuovoRuolo.Click
Try
Roles.CreateRole(txtNuovoRuolo.Text)
Aggiorna()
Catch ex As Exception
lblMessaggio.Text = ex.Message.ToString()
End Try
End Sub
Protected Sub btnCancellaRuolo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancellaRuolo.Click
lblMessaggio.Text = lstRuoli.SelectedItem.Value.ToString()
Aggiorna()
End Sub
End Class
In teoria il mio scopo era quello di far cancellare l'elemento con il metodo DeleteRole, ma mi sono accorto che non riesco neppure a prelevare l'elemento selezionato, perchè?