Question

This is a bit of an odd question, and I'm sure there was an easier way of doing this but...

I have a method that returns a List of names. I am parsing through this list with a foreach loop. I am adding each name to one long String so that I can set the text of a Table Cell to that string. But I can't seem to get it to add a new line. Is this possible?

Here's a snippet of the code:

Earlier my table loop:

TableCell tempCell = new TableCell();

The issue:

// Returns a List of Employees on the specified day and time.
List<string> EmployeeList = CheckForEmployees(currentDay, timeCount);

string PrintedList = "";
foreach (String s in EmployeeList)
{
    PrintedList += s;
    // PrintedList += s + System.Environment.NewLine;
    // PrintedList += s + " \n";
}
tempCell.Text = PrintedList;

Both the commented code lines didn't work. Any ideas?

Was it helpful?

Solution

You need to append a break tag since you want the new line to show in HTML. So append <br/>. I would also recommend using a stringbuilder if it is more than a few iterations.

OTHER TIPS

Table cell as in HTML table cell? Do you perhaps need to use the "br" tag instead of normal newline?

Another thing, you should use StringBuilder instead of doing string concatenation the way you do. Or even better, String.Join.

string PrintedList = String.Join("br-tag", EmployeeList);

Again, not sure if the br-tag is what you are after, but prefer to use the methods in the String class when possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top