|
-
Aug 29th, 2007, 07:34 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0] Convert HtmlTable to HTML source code
Hi,
consider the following code snippet:
Code:
HtmlTable table = new HtmlTable();
HtmlTableRow row1 = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
HtmlTableCell cell2 = new HtmlTableCell();
cell1.InnerText = "Test1";
cell2.InnerText = "Test2";
row1.Cells.Add(cell1);
row1.Cells.Add(cell2);
table.Rows.Add(row1);
Now my problem is that I want to obtain the HTML source code of the "table" such that I could output this in a browser control of a windows application. Anyone ever done this or can help me on this? I've tried using HtmlTextWriter with no success. I'm probably not doing the correct thing here...
-
Aug 29th, 2007, 08:29 AM
#2
Re: [2.0] Convert HtmlTable to HTML source code
Can you just write the HTML and set that to your WebBrowser's DocumentText property instead of doing all the other stuff?
Code:
private void button1_Click(object sender, EventArgs e)
{
string html = @"
<table border=""1"">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>";
this.webBrowser1.DocumentText = html;
}
-
Aug 29th, 2007, 01:44 PM
#3
Thread Starter
Hyperactive Member
Re: [2.0] Convert HtmlTable to HTML source code
The document I want to generate is far more complex than the sample I posted, so instead of having to recreate an HTML parser i'm looking at alternative solutions...
-
Aug 30th, 2007, 12:56 PM
#4
Re: [2.0] Convert HtmlTable to HTML source code
Would this do it?
Code:
using (MemoryStream dataStream = new MemoryStream())
{
using (StreamWriter textWriter = new StreamWriter(dataStream, Encoding.UTF8))
{
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(textWriter))
{
table.RenderControl(htmlWriter);
textWriter.Flush();
dataStream.Seek(0, SeekOrigin.Begin);
using (StreamReader dataReader = new StreamReader(dataStream))
{
string htmlContent = dataReader.ReadToEnd();
Console.WriteLine(htmlContent);
}
}
}
}
-
Aug 31st, 2007, 06:57 AM
#5
Thread Starter
Hyperactive Member
Re: [2.0] Convert HtmlTable to HTML source code
Yes, perfectly. Thanks!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|