0

I have set up the following method for multiple selection from user and store it in CSV format in Database.

<div class="col-md-10" style="padding-top: 7px;">
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="language" DataValueField="language" AutoPostBack="True" RepeatLayout="OrderedList" Width="432px">
    <asp:ListItem Value="Saturday">Saturday</asp:ListItem>
    <asp:ListItem Value="Sunday">Sunday</asp:ListItem>
    <asp:ListItem Value="Monday">Monday</asp:ListItem>
    <asp:ListItem Value="Tuesday">Tuesday</asp:ListItem>
    <asp:ListItem Value="Wednesday">Wednesday</asp:ListItem>
    <asp:ListItem Value="Thursday">Thursday</asp:ListItem>
    </asp:CheckBoxList>
</div>

private string CheckBoxListDataToCSV() 
{            
    string selectedItems = String.Join(",",
    CheckBoxList1.Items.OfType<ListItem>().Where(r => r.Selected)
        Select(r => r.Text));
    return selectedItems;
}

string str = CheckBoxListDataToCSV(); //This method to Add in datarow

My question is that how to populate back the values in their check boxes when Add/Edit activity perform. Thanking in Advance

hellow
  • 12,430
  • 7
  • 56
  • 79
ProgSMI
  • 79
  • 6
  • I think this is what you are looking for: https://stackoverflow.com/questions/23301832/populate-checkboxlist-with-items-from-database – Dimitri Sep 03 '18 at 13:08
  • 1
    Possible duplicate of [Populate checkboxlist with items from database?](https://stackoverflow.com/questions/23301832/populate-checkboxlist-with-items-from-database) – Feras Al Sous Sep 03 '18 at 14:22
  • I need to marked checks on store values that was first marked by the user, and was store in database in comma separated value format like 'monday,tuesday,thursday'. on update call these values get checked on screen – ProgSMI Sep 04 '18 at 02:27

1 Answers1

0

return dataset containing csv then

DataTable dt = dsPage.Tables[0];
            string strArr = dt.Rows[0]["Training_Days"].ToString();
            string[] Arr = strArr.Split(',');

            for (int j = 0; j < Arr.Length; j++)
            {
                for (int i = 0; i < Arr.Length; i++)
                {
                    if (CheckBoxList1.Items.FindByText(Arr[i]) != null)
                    {
                        CheckBoxList1.Items.FindByText(Arr[i]).Selected = true;
                        continue;
                    }
                }
            }
ProgSMI
  • 79
  • 6