asp.net - Build HTMLTable from C# Serverside with InnerHtml string -
asp.net - Build HTMLTable from C# Serverside with InnerHtml string -
i trying loop through client side html table contents on c# server side. setting html table runat="server"
not alternative because conflicts javascript in use.
i utilize ajax pass clientside html table's innerhtml server side method. thought able simple create htmltable
variable in c# , set innerhtml
property when realized not possible because got error {"'htmltable' not back upwards innerhtml property."}
for simplicity , lets innerhtml string passed client server is:
string myinnerhtml = "<colgroup>col width="100"/></colgroup><tbody><tr><td>hello</td></tr></tbody>"
i followed post stack overflow question can not quite working.
can point out errors?
string myinnerhtml = "<colgroup>col width="100"/></colgroup><tbody><tr><td>hello</td></tr></tbody>" htmltable table = new htmltable(); system.text.stringbuilder sb = new system.text.stringbuilder(myinnerhtml); system.io.stringwriter tw = new system.io.stringwriter(sb); htmltextwriter hw = new htmltextwriter(tw); table.rendercontrol(hw); (int = 0; < table.rows.count; i++) { (int c = 0; c < table.rows[i].cells.count; i++) { // cell contents } }
hope helps,
string myinnerhtml = @"<table> <colgroup>col width='100'/></colgroup> <tbody> <tr> <td>hello 1</td><td>hello 2</td> </tr> <tr> <td>hello 3</td><td>hello 4</td> </tr> </tbody> </table>"; dataset ds = new dataset(); ds.readxml(new xmltextreader(new stringreader(myinnerhtml))); var tr = ds.tables["tr"]; var td = ds.tables["td"]; foreach (datarow trrow in tr.rows) foreach(datarow tdrow in td.asenumerable().where(x => (int)x["tr_id"] == (int)trrow["tr_id"])) console.writeline( tdrow["tr_id"] + " | " + tdrow["td_text"]); output ========================= //0 | hello 1 //0 | hello 2 //1 | hello 3 //1 | hello 4
c# asp.net htmlcontrols
Comments
Post a Comment