Can I convert a dynamically created c# table to an html string ?
I mean like this;
Table t = new Table();
TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Text = "Some text... Istanbul";
tr.Cells.Add(td);
t.Rows.Add(tr);
t.ToString();
Response.Write(t.ToString());
I wanna see in the page;
<table> <tr> <td> Some text...
Istanbul </td> <tr> </table>
using (StringWriter sw = new StringWriter())
{
Table t = new Table();
TableRow tr = new TableRow();
TableCell td = new TableCell {Text = "Some text... Istanbul"};
tr.Cells.Add(td);
t.Rows.Add(tr);
t.RenderControl(new HtmlTextWriter(sw));
string html = sw.ToString();
}
result:
<table border="0"><tr><td>Some text... Istanbul</td></tr></table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With