Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have html page where there are many elements one of them is a table . How can i get the values in the table and append them to datatable i use html agility asp.net c#

this table is in scrpit code and have (\)with each item

HTML
<script type="text/javascript">
		<!--
		bklkl.abc.writeWidget({'cons':'bobj.crv.newpage'; style sheet properties with alot of character})



<\table cellspacing="0" cellpadding="3" rules="cols" id="page1">
    <\tr>
        <\th scope="col">h1</th>
        <\th scope="col">h2</th>
        <\th scope="col">h3 </th>
        <\th scope="col"> h4</th>
        <\th scope="col"> h5</th>
    <\tr>
    <\tr >
        <\td><input type="button" value="edit" /></td>
        <\td>value 1</td>
        <\td>value 2 </td>
        <\td>value 3</td>
        <\td>value 4</td>
    </tr>

<\table>
 //-->

    </script>



i cant get the table because of the css and java code ??
i even try

C#
string text = Regex.Replace(infodata.InnerText, @"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", string.Empty).Replace(@"\r\n", "").Replace(@"\", "").Replace(@"\r\", "");


but i get still css code that i cant reach or read the table

What I have tried:

This is my trial

<pre lang="C#">HtmlNodeCollection tables = pag1.Html.SelectNodes(&quot;//table[@id=&#39;data&#39;]&quot;);

DataTable tb = new DataTable();
HtmlNodeCollection rows = tables[0].SelectNodes(&quot;tr&quot;);

// create the columns
HtmlNodeCollection cols = rows[0].SelectNodes(&quot;th&quot;);
if (cols != null)
{
for (int j = 0; j &lt;= cols.Count - 1; j++)
{
tb.Columns.Add(cols[j].InnerText);
}
}

// Now fill the table
for (int i = 0; i &lt;= rows.Count - 1; i++)
{
var newRow = tb.NewRow();
HtmlNodeCollection cols = rows[i].SelectNodes(&quot;td&quot;);
if (cols != null)
{
for (int j = 0; j &lt;= cols.Count - 1; j++)
{
newRow[j] = cols[j].InnerText;
}

}

// add the row to table
tb.Rows.Add(newRow);
}
Posted
Updated 19-Dec-16 3:29am

1 solution

Well, your table is a HTML construct it is not a control, so if you post your page to the server it will not contain anything from a HTML table.

What you can do is get the data on the client, in your case with

JavaScript
var lotofrawhtml = $("page1").html();

What you need to understand is that an ADO.DataTable DataTables[^] is not the same as a html table HTML table tag[^]

now what you can do is for instance put style classes on your data and then select that and do something with it like this Tryit Editor v3.3[^]

What that could be is posting it to some service with this technique jQuery.post() | jQuery API Documentation[^] ... but you will have to roll up your sleeves and get your hands dirty ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900