HTML Agility Pack tr insertion at the end of a table

c# html-agility-pack

Question

I own this desk.

<div id="ConversationDIv" runat="server">
   <table border="1" id="tbl">
       <tr>
          <td>blah blah</td>
       </tr>
   </table>
</div>
<asp:Button id="Insert" onCLick="Insert_Click" Text="addNew" ></asp:Button>

c#:

protected void Insert_Click(object sender,EventArgs e)
{
    var html = new HtmlAgilityPack.HtmlDocument();

    html.LoadHtml(ConversationDIv.InnerHtml);

    var table = html.DocumentNode.SelectNodes("table").FirstOrDefault();
    // how can I add a new row to table ?
}

How can I add a new row to the table if I wish to?

1
1
8/23/2014 4:10:31 PM

Popular Answer

Zzz-5-Zzz may be used to choose a table. Additionally, when creating a node from an html string, use the syntax HtmlNode.CreateNode:

var table = html.DocumentNode.SelectSingleNode("//table");
table.AppendChild(HtmlNode.CreateNode("<tr></tr>"));
4
9/3/2013 8:09:09 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow