deleyd
asked on
Generating HTML in C#
I have some C# code which looks something like this:
using (StreamWriter output = new StreamWriter(filename)
{
output.Write("<HTML>");
output.Write("<HEAD>...</HEAD>");
output.Write("<BODY>");
output.Write("<TABLE>");
output.Write( table header stuff);
// Now we output the HTML Table rows of data
foreach(MyData data in myDataList)
{
output.Write("<tr><td>" + data.column1 + "</td><td>" + data.column2 + "</td><td>" + data.column3 + "</td></tr>");
}
output.Write("</TABLE>");
output.Write("</BODY>");
output.Write("</HTML>");
}
My question is, is there a better way of doing this? Can I somehow create a template, which looks like an HTML file, something like:template =
<HTML>
<HEAD>
...
</HEAD>
<BODY>
<TABLE>
<tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
{magically fill in rows here from data}
</TABLE>
</BODY>
</HTML>
This looks nice, all except how would I get my C# code to "magically fill in rows here from data"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.