Using the ListBox control (VB) : ListBox « ASP.net Controls « ASP.NET Tutorial






<%@ 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 = "You selected from the 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>Using the 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="Add an additional item" 
         OnClick="Button1_Click" />
        <br />
        <br />
    
        <asp:ListBox ID="ListBox1" Runat="server" SelectionMode="multiple">
           <asp:ListItem>Hematite</asp:ListItem>
           <asp:ListItem>Halite</asp:ListItem>
           <asp:ListItem>Limonite</asp:ListItem>
           <asp:ListItem>Magnetite</asp:ListItem>
        </asp:ListBox>
        <br />
        <br />
        <asp:Button ID="Button2" Runat="server" Text="Submit" 
         OnClick="Button2_Click" />
        <br />
        <br />
        <asp:Label ID="Label1" Runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>








3.16.ListBox
3.16.1.asp:ListBox OnSelectedIndexChanged event and AutoPostBack (VB.net)
3.16.2.Fill value to asp:ListBox in asp:RadioButtonList selection changed action (VB.net)
3.16.3.Bind array data to asp:ListBox (VB.net)
3.16.4.Bind asp:Label with asp:ListBox (VB.net)
3.16.5.Set array value to asp:ListBox DataSource (VB.net)
3.16.6.Selection mode of asp:ListBox (C#)
3.16.7.Selection mode of asp:ListBox (VB)
3.16.8.Using the ListBox control (C#)
3.16.9.Using the ListBox control (VB)
3.16.10.Property tester