1

I have a Checkboxlist like this

   <asp:CheckBoxList ID="CheckBoxList1" runat="server" ForeColor="White" Height="156px"
        Visible="False" Width="106px">
        <asp:ListItem Value="1">Monday</asp:ListItem>
        <asp:ListItem Value="2">Tuesday</asp:ListItem>
        <asp:ListItem Value="3">Wednesday</asp:ListItem>
        <asp:ListItem Value="4">Thursday</asp:ListItem>
        <asp:ListItem Value="5">Friday</asp:ListItem>
        <asp:ListItem Value="6">Saturday</asp:ListItem>
        <asp:ListItem Value="7">Sunday</asp:ListItem>
    </asp:CheckBoxList>

I have retrieved values from the database and I am splitting the values like this

    string s = TextBox2.Text;
    string[] values = s.Split(',');

For example: if I have 2,3,6 in the textbox, I need to check ListItem 2,3,6.

1 Answer 1

1

This loop should work as expected:

foreach(ListItem item in CheckBoxList1.Items)
    item.Selected = values.Contains(item.Value);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.