Selection mode of asp:ListBox (VB) : ListBox « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="vb" Explicit="true" Strict="true" %>
<script language="vb" runat="Server">
    Public Sub Verify(sender As Object, e As EventArgs)
        Dim lstItem As ListItem
        If CountryListBox.SelectedIndex <> -1 Then
            OutputLabel.Text = "You selected: "
            If CountryListBox.SelectionMode = ListSelectionMode.Single Then
                OutputLabel.Text += "<b>" & CountryListBox.SelectedItem.Text & "</b>"
            Else
                For Each lstItem In CountryListBox.Items
                    If lstItem.Selected Then
                        OutputLabel.Text += "<b>" & lstItem.Text & "</b>, "
                    End If
                Next
            End If
        Else
            OutputLabel.Text = "You didn't selected any country!"
        End If
    End Sub
</script>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <asp:ListBox ID="CountryListBox" Runat="server" SelectionMode="Multiple">
        <asp:ListItem Value="1">United States</asp:ListItem>
        <asp:ListItem Value="2">United Kingdom</asp:ListItem>
        <asp:ListItem Value="3">China</asp:ListItem>
        <asp:ListItem Value="4">India</asp:ListItem>
      </asp:ListBox><br>
      <asp:Button ID="SubmitButton" Runat="server" Text="Submit" OnClick="Verify"></asp:Button>
      <asp:Label ID="OutputLabel" Runat="server"></asp:Label>
    </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