J'ai cette table
<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 ?
}
Je veux ajouter une nouvelle ligne à la table, comment puis-je faire cela?
Vous pouvez utiliser SelectSingleNode pour sélectionner une table. Et utilisez HtmlNode.CreateNode pour créer un noeud ajouté à partir de la chaîne html:
var table = html.DocumentNode.SelectSingleNode("//table");
table.AppendChild(HtmlNode.CreateNode("<tr></tr>"));