htmlページには多くの要素がありますが、そのうちの1つはテーブルです。どのように私は、テーブル内の値を取得し、私が使用してグリッドビューにHTML敏捷性のasp.net C#のhtmlテーブルからfillviewを作成するC#
それらを追加することができますこれは私の裁判
HtmlNodeCollection tables = pag1.Html.SelectNodes("//table[@id='data']");
DataTable tb = new DataTable();
HtmlNodeCollection rows = tables[0].SelectNodes("tr");
for (int i = 0; i <= rows.Count - 1; i++)
{
HtmlNodeCollection cols = rows[i].SelectNodes("td");
if (cols != null)
{
for (int j = 0; j <= cols.Count - 1; j++)
{
tb.Columns.Add(cols[j].InnerText);
}
}
}
GridView1.DataSource = tb;
GridView1.DataBind();
この表
<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" onclick="javascript:__doPostBack()" /></td>
<td>value 1</td>
<td>value 2 </td>
<td>value 3</td>
<td>value 4</td>
</tr>
<tr>
<td><input type="button" value="edit" onclick="javascript:__doPostBack()" /></td>
<td>value 1</td>
<td>value 2 </td>
<td>value 3</td>
<td>value 4</td>
</tr>
<tr>
<td><input type="button" value="edit" onclick="javascript:__doPostBack()" /></td>
<td>value 1</td>
<td>value 2 </td>
<td>value 3</td>
<td>value 4</td>
</tr>
</table>
何が問題なのですか? – CodingYoshi
エラーが発生しました 'xxx'という名前の列が既にこのDataTableに属しています。テーブルのヘッダーを取得できません –
テーブルのHTMLを確認できますか – CodingYoshi