<%@ Page Language="VB" %>

<script runat="server">
    Protected Sub Button1_Click(ByVal sender As Object, _
       ByVal e As System.EventArgs)

        ListBox1.Items.Add(TextBox1.Text.ToString())
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, _
       ByVal e As System.EventArgs)

        Label1.Text = "Wybrałeś z ListBox:<br>"
        For Each li As ListItem In ListBox1.Items
            If li.Selected = True Then
                label1.Text += li.Text & "<br>"
            End If
        Next
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Korzystanie z ListBox</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Dodaj kolejny element" 
         OnClick="Button1_Click" /><br /><br />
    
        <asp:ListBox ID="ListBox1" runat="server" SelectionMode="multiple">
           <asp:ListItem>Hematyt</asp:ListItem>
           <asp:ListItem>Halit</asp:ListItem>
           <asp:ListItem>Limonit</asp:ListItem>
           <asp:ListItem>Magnetyt</asp:ListItem>
        </asp:ListBox><br /><br />

        <asp:Button ID="Button2" runat="server" Text="Zatwierdź" 
         OnClick="Button2_Click" /><br /><br />

        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
