Click here to Skip to main content
15,881,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is what i get from online, where should i put in? or is it got any other solution to doing it? Please help me, Thanks a lot

C#
Set:

        string s = string.Empty;
        foreach (ListItem  itm in CheckBoxList1.Items)
        {
            if (itm.Selected)
            {
                s += itm.Value + "$";
            }
        }
 Get:

        string[] sl = s.Split("$");
        foreach (string  s in sl)
        {
            ListItem itm = CheckBoxList1.Items.FindByValue(s);
            if (itm != null) itm.Selected = true;
        }
Posted

1 solution

Put this as a property in your code behind:

C#
public partial class WhateverYourClassNameIs
{
  public String[] Selections //<-- change this to private if not being accessed to other classes.
  {
    get
    {
      string[] sl = s.Split("$");
      foreach (string  s in sl)
      {
        ListItem itm = CheckBoxList1.Items.FindByValue(s);
        if (itm != null) itm.Selected = true;
      }
    }
    set
    {
      string s = string.Empty;
      foreach (ListItem  itm in CheckBoxList1.Items)
      {
        if (itm.Selected)
        {
          s += itm.Value + "$";
        }
      }
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900