Ho questo tavolo
<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 ?
}
Voglio aggiungere una nuova riga alla tabella come posso fare questo?
È possibile utilizzare SelectSingleNode per selezionare la tabella. E usa HtmlNode.CreateNode per creare un nodo aggiunto da una stringa html:
var table = html.DocumentNode.SelectSingleNode("//table");
table.AppendChild(HtmlNode.CreateNode("<tr></tr>"));