the easy yet nicest way, would be with XSLT.
You produce an XML structure with your data (piss easy).
You 'transofrm' that XML into HTML.
so you have a class like
Code:
public class FOO {
public string Feild1 {get;set;}
public string Feild2 {get;set;}
}
you then serialize that, with the XML seriealizer, but we don't want to write it to a file, so we do it to a stirng.
Code:
// serialize data to xml string.
StringBuilder xmlsb = new StringBuilder();
XmlWriter xmlWriter = XmlWriter.Create(xmlsb);
XmlSerializer xmlSerializer = new XmlSerializer(typeof (FOO[]));
// an array of FOO.
xmlSerializer.Serialize(xmlWriter, new FOO[] {foo1,foo2});
Then we load the compiled Transform.
Code:
XslCompiledTransform t = new XslCompiledTransform(false);
t.Load(@"report.xslt");
TextReader tr = new StringReader(xmlsb.ToString());
XmlReader xmlR = XmlReader.Create(tr);
StringBuilder sb = new StringBuilder();
XmlWriter xmlW = XmlWriter.Create(sb);
t.Transform(xmlR, xmlW);
xmlWriter.Close();
That expects an XSLT file called report.
your then left with a string builder (sb) that has the 'transformed' XML in HTML.
Its really easy to debug and maintain, plus going forward you have the XML which is always useful for interopping with other apps.