madhu
madhu

Reputation: 21

Unable to add a row to a HTML table dynamically

I am unable to add a row to a HTML table dynamically. I am using IHtmlDocument2 to create tr and td elements and IHtmlElement to set attributes and IHtmlDomNode to add created node to the document hierarchy.

Please anyone help me to solve the above problem.

I am traversing through the document when I get the tr tag I have created the tr element using CreateElement, then I use InsertBefore to insert it into the document but it's not working.

I've tried for one week but didn't get anything working.

Upvotes: 1

Views: 349

Answers (3)

Swanny
Swanny

Reputation: 2418

Probably a little late. I've been recently replacing a .Net app that used to use the old DHTML control, but to get it to work under Windows 7 I've had to replace this with the WebBrowser control which represents a significant step backward in functionality. I've been using the underlying IHtmlDocument2 interface to work with it. In this case I "cheated" and just built the table up in raw HTML, pasted it to the clipboard as HTML, then use execCommand("Paste") of the interface. This was wrapped within a clipboard preserver so the original clipboard state was restored.

Upvotes: 0

Salman Arshad
Salman Arshad

Reputation: 272096

I suggest that you start using a JavaScript framework such a jQuery or Prototype. Either of these will allow you to achieve the functionality with one line of JavaScript code regardless of which browser you have. Using Prototype for example:

$$('table#mytable').insert({bottom: '<tr><td>some html</td></tr>'})

Upvotes: 1

Patrick Bergner
Patrick Bergner

Reputation: 623

With jQuery it's

$('table#mytable').append('<tr><td>some html</td></tr>');

Upvotes: 0

Related Questions