我需要从HTML表中提取一些文本
我试过用
tblGridHeader.Rows[0].InnerText.ToString()
但我得到了错误
“HTMLTableRow”不支持InnerText属性 .
我也试过InnerHTML,但仍然没有去 .
我确实尝试使用cells属性,但是我收到了错误
指定的参数超出了有效值的范围 .
Note: 我刚刚在静态表上尝试了cells属性,但它确实有效 . 所以我想这与我的表动态填充有关?
视觉工作室编辑的代码:
<div id="divGridHeader" runat="Server" style="width:771px; text-align:left; overflow:hidden; float:left">
<table cellpadding="0" cellspacing="0" border="0" id="tblGridHeader" runat="Server">
<tr id="trMonth" runat="Server" class="fixedHeader">
</tr>
<tr id="trDaysOfWeek" runat="Server" class="fixedHeader">
</tr>
<tr id="trDaysInMonth" runat="Server" class="fixedHeader">
</tr>
<tr id="trFteLimit" runat="Server" class="fixedHeader" style="color:Black">
</tr>
</table>
</div>
浏览器代码:
<div id="ctl00_cphWorkforceScheduler_divGridHeader" style="overflow: hidden; width: 771px; text-align: left; float: left;">
<table id="ctl00_cphWorkforceScheduler_tblGridHeader" cellspacing="0" cellpadding="0" border="0" width="1085">
<tbody>
<tr id="ctl00_cphWorkforceScheduler_trMonth" class="fixedHeader">
</tr>
<tr id="ctl00_cphWorkforceScheduler_trDaysOfWeek" class="fixedHeader">
</tr>
<tr id="ctl00_cphWorkforceScheduler_trDaysInMonth" class="fixedHeader">
<th id="ctl00_cphWorkforceScheduler_thDay_10012010120000AM" class="tt" onmouseout="HideToolTip(ctl00_cphWorkforceScheduler_spnWorkforceToolTip_ctl00_cphWorkforceScheduler_thDay_10012010120000AM, ctl00_cphWorkforceScheduler_spnWorkforceToolTipMiddle_ctl00_cphWorkforceScheduler_thDay_10012010120000AM);" onmouseover="ShowToolTip(ctl00_cphWorkforceScheduler_spnWorkforceToolTip_ctl00_cphWorkforceScheduler_thDay_10012010120000AM, ctl00_cphWorkforceScheduler_spnWorkforceToolTipMiddle_ctl00_cphWorkforceScheduler_thDay_10012010120000AM, '135px');" style="background-repeat: repeat-x; text-align: center; font-size: 8pt; font-weight: normal; background-image: url(../Images/TitleGradientMiddle.JPG); height: 20px; width: 35px; text-decoration: none;">
</th>
<th id="ctl00_cphWorkforceScheduler_thDay_10022010120000AM" class="tt" onmouseout="HideToolTip(ctl00_cphWorkforceScheduler_spnWorkforceToolTip_ctl00_cphWorkforceScheduler_thDay_10022010120000AM, ctl00_cphWorkforceScheduler_spnWorkforceToolTipMiddle_ctl00_cphWorkforceScheduler_thDay_10022010120000AM);" onmouseover="ShowToolTip(ctl00_cphWorkforceScheduler_spnWorkforceToolTip_ctl00_cphWorkforceScheduler_thDay_10022010120000AM, ctl00_cphWorkforceScheduler_spnWorkforceToolTipMiddle_ctl00_cphWorkforceScheduler_thDay_10022010120000AM, '135px');" style="background-repeat: repeat-x; text-align: center; font-size: 8pt; font-weight: normal; background-image: url(../Images/TitleGradientMiddle.JPG); height: 20px; width: 35px; text-decoration: none;">
等等,我没有粘贴所有内容,因为有很多标签 . 请假设HTML格式正确 .
6 回答
如果你有TD的runat =“server”,你可以在代码隐藏中读取它
和我的代码隐藏
这来自我测试的一个工作示例
我不是一个网络人,但快速访问MSDN揭示了HTMLTableRow.Cells属性 .
HTMLTableRow
控件不能包含文本,它们只能包含其他控件 . 你准备做什么?您可能应该查看HTMLTableRow
的Controls
或Cells
集合,然后检查其子项的文本(或其他子控件) .尝试类似的东西
假设您想要行的第一个单元格中的文本内容 .
尝试
看起来不支持:
http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltablerow.innertext%28v=VS.71%29.aspx
你试过读过每一行的细胞吗?
这样的事可能吗?