I have a table object and I want to render it as html into a string. I've been looking at htmltextwriters etc but a touch confused.
Any help appreicated :]
Printable View
I have a table object and I want to render it as html into a string. I've been looking at htmltextwriters etc but a touch confused.
Any help appreicated :]
You want put the output of your control's render method into a string ? Normally, you just use RenderContents(htmlwriter).
But this should get you started:
Code:System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.TextWriter t = new System.IO.StreamWriter(stream);
System.Web.UI.HtmlTextWriter h = new System.Web.UI.HtmlTextWriter(t);
System.Web.UI.WebControls.Table table = new Table();
table.Height = 200;
table.RenderControl(h);
h.InnerWriter.Flush();
byte[] r = new byte[stream.Length];
stream.Seek(0,System.IO.SeekOrigin.Begin);
stream.Read(r,0,r.Length);
result = System.Text.Encoding.ASCII.GetString(r,0,r.Length);