I have the following CheckBoxList:
<asp:CheckBoxList ID="CheckBoxList" runat="server" RepeatColumns="2" RepeatDirection="Horizontal" Width="75%" Height="80px" CellPadding="2" CellSpacing="1" OnSelectedIndexChanged="CheckBoxList2_SelectedIndexChanged"> <asp:ListItem Text="Option 1" Value="Option 1" /> <asp:ListItem Text="Option 2" Value="Option 2"></asp:ListItem> <asp:ListItem Text="Option 3" Value="Option 3" /> <asp:ListItem Text="Option 4" Value="Option 4" /> </asp:CheckBoxList>
In the aspx.cs file, I have:
foreach (var item1 in CheckBoxList.Items.Cast<ListItem>().Where(item1 => item1.Selected)) { { Optional = Optional + item1.Text; } }
The issue I am having is: When I do not check the first option and check 2 or 3 of the other options, only the first option of that selection will appear in the output. If I select option 1 and any other option everything works the way it is supposed to be. But lets say if I select option 2 and option 3. Only option 2 will appear.