How to read html table in c# [closed]

<table id="mytable" runat="server"> <thead> <tr> <td > </td> <td> Minute </td> <td Category Name </td> </tr> </thead> <tbody> <tr> <td > 10 </td> <td> </td> <td> <span></span> </td> </tr> <tr > <td> </td> <td> 15 </td> <td> <span></span> </td> </tr> </table>

This is my html table Here i have to find first cell second cell third cell data of each row in c# How can i find.


You may try Html agility pack API to parse the html text.


One option is to make the cells into server controls by adding an id and runat=server attributes and then you can access them as htmlcontrols -

You could then use a repeater to generate each row. Then create a method for the ItemDataBound event of the repeater -

This allows you to populate the data initially from a suitable data source and if your data source changes, you can simply rebind the source to the repeater to get it to update.

Example of how to find span tag :

<span id="span1" runat="server"></span>

Add the attributes as above.

Then within the repeater ItemDataBound method

e.Item.FindControl("span1")).innerText= "Hello John";

Note the use of the innerText method to add content within the span tags.

You only need to make the specific elements you need into server controls.

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:How to read html table in c# [closed]