我在表单视图中有一个html表。我把它设为runat =" server"但在服务器端,id-tblDemandData无法访问它。我的代码是 -
<asp:FormView ID="DemandDataView" runat="server">
<ItemTemplate>
<div id="DemandDataDIV" runat="server" visible="true">
<asp:Button Text="exportBtn" runat="server" ID="btnExport" OnClick="btnExport_Click" />
<hr />
<div class="headingtext" runat="server" id="tblDiv" style="width: 100%; margin-bottom: 10px;"><%= LocalString("DemandDataText")%></div>
<table border="0" runat="server" id="tblDemandData" cellpadding="3" cellspacing="0" class="tabletext">
<tr>
<td class="tabletextbold" style="width: 240px;text-align:right"></td>
<td class="tabletextbold" style="width: 151px;text-align:right"><%= LocalString("PhaseAText")%></td>
<td class="tabletextbold" style="width: 240px;text-align:right"><%= LocalString("PhaseBText")%></td>
<td class="tabletextbold" style="width: 151px; text-align: right"><%= LocalString("PhasecText")%></td>
<td class="tabletextbold" style="width: 240px;text-align:right">Total</td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageABText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstantaneousVoltagePhaseAB", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px; text-align: right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageBCText") %></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousVoltagePhaseBC", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageCAText") %></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px; text-align: right"><%# Eval("InstantaneousVoltagePhaseCA", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageAngleABText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstantaneousVoltagePhaseAB", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px; text-align: right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageAngleBCText") %></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousVoltagePhaseBC", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageAngleCAText") %></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px; text-align: right"><%# Eval("InstantaneousVoltagePhaseCA", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("VoltageHarmonicdistorsionText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstantaneousVoltageHarmonicDistortionPhaseA", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousVoltageHarmonicDistortionPhaseB", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%# Eval("InstantaneousVoltageHarmonicDistortionPhaseC", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("CurrentHarmonicdistorsionText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("IharmPhaseAPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("IharmPhaseBPV", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%# Eval("IharmPhaseCPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("DistorsionPowerText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstantaneousDistorsivePowerPhaseA", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousDistorsivePowerPhaseB", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%# Eval("InstantaneousDistorsivePowerPhaseC", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousDistorsivePowerThreePhase", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("PowerFactorText") %></td>
<td style="width: 151px;"></td>
<td style="width: 240px;"></td>
<td style="width: 151px;"></td>
<td style="width: 240px;"></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("ActivePowerText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstActiveKWA1", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstActiveKWB1", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%# Eval("InstActiveKWC1", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("instKW", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("ApparentVAText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("VAarithPhaseAPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("VAarithPhaseBPV", "{0:N4}")%></td>
<td style="width: 151px; text-align: right"><%# Eval("VAarithPhaseCPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstVArms", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("ApparentVAPFText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("instPFA1", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("instPFB1", "{0:N4}")%></td>
<td style="width: 151px;text-align:right"><%# Eval("instPFC1", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("PFinstAVA", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("ReactivePowerText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstVARA1", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstVARB1", "{0:N4}")%></td>
<td style="width: 151px;text-align:right"><%# Eval("InstVARC1", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("ArithmeticVARSysPV", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("ReactiveVARPFText") %></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%# Eval("PFinstAVAR", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("PhaseorVAText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("PVAPhaseAPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("PhaseAPVBI", "{0:N4}")%></td>
<td style="width: 151px;text-align:right"><%# Eval("PVAPhaseCPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("instVA", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("PhaseorVAPFText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstantaneousCosinePhaseA", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousCosinePhaseA", "{0:N4}")%></td>
<td style="width: 151px;text-align:right"><%# Eval("InstantaneousCosinePhaseA", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstantaneousCosineThreePhase", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("PhaseorVARText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("VARPhaseAPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("VARPhaseBPV", "{0:N4}")%></td>
<td style="width: 151px;text-align:right"><%# Eval("VARPhaseCPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("InstVARTimeDelay", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("PhaseorVARPFText") %></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%# Eval("PFinstPVAR", "{0:N4}")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("PFAngleText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("PFanglePhaseAPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%# Eval("PFanglePhaseBPV", "{0:N4}")%></td>
<td style="width: 151px;text-align:right"><%# Eval("PFanglePhaseCPV", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("FrequencyText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("InstFREQ", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
</tr>
<tr>
<td class="tabletextbold" style="width: 240px;"><%= LocalString("TempratureText") %></td>
<td style="width: 151px;text-align:right"><%# Eval("temperature", "{0:N4}")%></td>
<td style="width: 240px;text-align:right"><%= LocalString("NAText")%></td>
<td style="width: 151px;text-align:right"><%= LocalString("NAText") %></td>
<td style="width: 240px;text-align:right">
<%= LocalString("NAText")%>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:FormView>
请帮我解决我的错误。
答案 0 :(得分:2)
您需要通过FromView
访问其ItemTemplate
HtmlTable table = (HtmlTable)DemandDataView.FindControl("tblDemandData");
答案 1 :(得分:0)
有两个选项 -
选项1.(最推荐) - 您可以尝试使用Html agility pack API来解析html文本。HTML Agility Pack
选项2.使用String Builder将func queue() -> SnapOperationQueue {
switch self {
case .Highest:
return SnapOperationQueue(queue: .Highest)
case .High:
return SnapOperationQueue(queue: .High)
case .Normal:
return SnapOperationQueue(queue: .Normal)
case Low:
return SnapOperationQueue(queue: .Low)
default:
return self
}
}
代码附加到String Builder变量并将其传递给html代码。样品在下面 -
Pass Html Table to Aspx With String Builder
答案 2 :(得分:0)
如前所述,您应该在表的父控件上使用FindControl(&#34; YourControlID&#34;)。请注意,FindControl只能在第一级子控件中迭代,就像我记得的那样..
答案 3 :(得分:0)
这对我有用,请检查一下..
只需在代码<asp:TemplateField>
的顶部添加<itemtemplate>
。