Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
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
 
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 8-Nov-12 15:29pm


1 solution

Put this as a property in your code behind:
 
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 + "$";
        }
      }
    }
  }
}
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,959
1 Prasad_Kulkarni 3,679
2 OriginalGriff 3,384
3 _Amy 3,332
4 CPallini 2,925


Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid