FLAME ON!
var html = "";
html += "<table class='colorful'>";
foreach(var item in collection) {
html += "<tr>";
html += "<td class='boldCell'>" + item.PropWhatever + "</td>";
// more cells here as needed
html += "</tr>";
}
html += "</table>";
placeholder1.InnerHtml = html;
I will prob get downvoted for this, but as a former designer who had to tweak HTML in code before I really knew much about .NET, the above code was way easier to understand than the methods that abstract HTML creation. If you think a designer might ever have to tweak your HTML, use simple strings like this.
Something I see a lot of devs miss when they write HTML in code is that in HTML, single or double quotes are allowed for attributes. So instead of escaping all the quotes in code (which looks wanky as hell to the non-initiated), just use single quotes for the html quotes inside your strings.
FINE. All you string concatenating haters are crampin' my rep. Here's the 'proper' way to do this without string concatenation, but I stand by my opinion that any normal page with normal tables won't present any performance problems outside of some ridiculous Google-like scale:
var sb = new System.Text.StringBuilder();
sb.Append("<table class='colorful'>");
foreach (var item in collection)
{
sb.Append("<tr>");
sb.Append("<td class='boldCell'>" + item.PropWhatever + "</td>");
// more cells here as needed
sb.Append("</tr>");
}
sb.Append("</table>");
placeholder1.InnerHtml = sb.ToString();