I have a listbox and want to show all of the selected values in a label.
I have tried the code below but can't get more than one value to show.
I think this is something simple but can't figure it out. Can anyone point me in the right direction?
I have tried the code below but can't get more than one value to show.
I think this is something simple but can't figure it out. Can anyone point me in the right direction?
VB.NET:
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">
<asp:ListItem>Monday</asp:ListItem>
<asp:ListItem>Tuesday</asp:ListItem>
<asp:ListItem>Wednesday</asp:ListItem>
<asp:ListItem>Thursday</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
</div>
</form>
VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For Each item As ListItem In ListBox1.Items
If item.Selected = True Then
Label1.Text = item.Text
End If
Next
End Sub