Writting to a TextBox

  • Thread starter Thread starter C#Schroeder
  • Start date Start date
C

C#Schroeder

I want to create an ArrayList of names ("Tony","Robin","Johnson") on
one page and then on another page I want to populate a TextBox field
with those names from the Arraylist. How do I populate the TextBox?
 
C#Schroeder said:
I want to create an ArrayList of names ("Tony","Robin","Johnson") on
one page and then on another page I want to populate a TextBox field
with those names from the Arraylist. How do I populate the TextBox?

Enumerate the list, forming a string from the names (using whatever
delimiters, if any, you desire of course), and then set the text of the
TextBox to that string.
 
The best way to enumerate the list is:
string[] names = (string[])list.ToArray(typeof(string));
textbox1.Text = string.Join("\r\n",names);


Ciaran O'Donnell
 
Or
object[] names = list.ToArray();
string.Concat(names);

this might be better because the arraylist doesnt copy the internal array
for this but the string.concat does a bit more work. This would use less
memory though.

Ciaran O'Donnell
 
Scrub this one, the ToArray() does copy the array so the other one is better.

Ciaran O''Donnell said:
Or
object[] names = list.ToArray();
string.Concat(names);

this might be better because the arraylist doesnt copy the internal array
for this but the string.concat does a bit more work. This would use less
memory though.

Ciaran O'Donnell

Peter Duniho said:
Enumerate the list, forming a string from the names (using whatever
delimiters, if any, you desire of course), and then set the text of the
TextBox to that string.
 
Thanks to everyone for the help. It works
Ciaran said:
Scrub this one, the ToArray() does copy the array so the other one is better.

Ciaran O''Donnell said:
Or
object[] names = list.ToArray();
string.Concat(names);

this might be better because the arraylist doesnt copy the internal array
for this but the string.concat does a bit more work. This would use less
memory though.

Ciaran O'Donnell

Peter Duniho said:
I want to create an ArrayList of names ("Tony","Robin","Johnson") on
one page and then on another page I want to populate a TextBox field
with those names from the Arraylist. How do I populate the TextBox?

Enumerate the list, forming a string from the names (using whatever
delimiters, if any, you desire of course), and then set the text of the
TextBox to that string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top