populating list box in ASP.NET

i have a variable kind of like this

variable1 = item1;item2;item3;item4;

everytime there is a ";" i want to break the variable and put that item in listbox.

list box should look like this.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try this:

Dim arr as String()
Dim variable1 as String = "item1;item2;item3;item4"

arr = variable1.Split(";")

MyListBox.DataSource = arr

pratikshahseAuthor Commented:
what should be the mylistbox.datatextfield.

should it be

mylistbox.datatextfield = variable1
I tried pratikshahse's answer and it works.

In one line it is: listBox1.DataSource = textBox1.Text.Split(';');

There is no need to use datatextfield, DataSource  works.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

" I tried pratikshahse's answer and it works."

I copied and pasted the wrong name, sorry Arthur_Wood.
pratikshahseAuthor Commented:
when i copy AW's code and paste it in page load my list box stay empty. nothing shows up
Whoops, my bad, i did that in a windows app (i guess the 2 listboxes are not the same).

Have a wack @ this: (C#)

string str = "item1;item2;item3;item4";
string[] items = str.Split(';');
foreach(string item in items)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pratikshahseAuthor Commented:
unexplained ways do you have anything in vb. not familiar with c# that much.

thank you
Carl TawnSystems and Integration DeveloperCommented:
Not after any points for this, but here's a slightly shorter version. Not necessarily any better/faster, I just like as few a lines of code as possible :o)

        Dim variable1 As String = "item1;item2;item3;item4"
        For Each s As String In variable1.Split(";")
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.