Thursday, December 31, 2009

Some time back while looking around for something else, I was stumbled upon this class, and I simply enjoy using it!

A "wow"-class; I would say. Though, not a lot of documentation is available, but it is worth using this class for those who frequently manage in-memory data with lists/arrays/etc.

A not-so-cool code, somewhere in the asp.net page, goes as follows:

ListBox ctl = ((ListBox)someControlHolder.FindControl("objControl" + i.ToString()));
for (int j = 0; j < ctl.Items.Count; j++)
{
   if (ctl.Items[j].Selected)
   str +=ctl.Items[j].Text + ",";//make it comma separated.
}
str.Remove(str.ToString().Length - 1, 1); //remove the last extra comma.

or And for oCommaDelimitedStringCollection reason, a cool/neat/clean is as follows:
ListBox ctl = ((ListBox)someControlHolder.FindControl("objControl" + i.ToString()));
CommaDelimitedStringCollection strCsv = new CommaDelimitedStringCollection();
for (int j = 0; j < ctl.Items.Count; j++)
{
  if (ctl.Items[j].Selected)
  {
   strCsv.Add(ctl.Items[j].Text);
  }
}

And yes, you are right, doing strCsv.ToString() will write the comma separated string (0:

Enjoy...!

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Blogger templates

Withoutbugs. Powered by Blogger.

Category

Technology (70) Business (7) Meta (7) thoughts (5) life (3)

Ads Banner

There was an error in this gadget

Formulir Kontak

Name

Email *

Message *

Followers

WITHOUTbugs.com is the best blog full of Great Ideas, Business, Technology, Life Hacks, Thoughts, M

Views

Topads

Join our Team

Video of the Day

- Copyright © WITHOUTbugs.com is the best blog full of Great Ideas, Business, Technology, Life Hacks, Thoughts, M - WithoutBugs- Powered by Blogger | WithoutBugs -