我有一个包含三个HTML表的aspx页面。HTML中的一个表如下所示:
<table id='example' >
<thead>
<tr>
<th><INPUT type="checkbox" onchange="checkAll(this)" name="chk[]"/></th>
<th>SchoolID</th>
...
</tr>
</thead>
<tr>
<td>
<input type='checkbox' name='name0' />
</td>
<td>200116</td>
</tr>
<tr>
<td>
<input type='checkbox' name='name1' />
</td>
<td>200116</td>
</tr>
...
</table>
我需要的是拿到
SchoolID
用于最终用户在C#中检查的行。最好的方法是什么?
我目前正在尝试使用HTMLAgilityPack将我的HTML表作为Datatable,但没有成功。这是第一张桌子,我需要第三张。然而,我不确定这是否是最好的方式。请告知。
var doc = new HtmlDocument();
//doc.Load(Request.Url.ToString()); //gives error.
doc.Load(filepath); //this works
//this is returning me the first table of my page, i need the third table.
var nodes = doc.DocumentNode.SelectNodes("//table/tr");
var table = new DataTable("exampleDataTable");
编辑:原来我不能使用HTMLAgilityPack,因为我实际上是在用C#创建表,然后发送到前端。使用filepath不起作用,因为默认情况下.aspx文件中没有表。
EDIT2:Sec,我找到了web.load函数,也许我可以使用Request.Url。