在嵌套表中查找HTML控件 [英] Find HTML control in nested table
问题描述
大家好
我编写生成动态表格的代码,作为输出:
< table id =edListdir =rtlcellspacing =0cellpadding =0width =100%align =center>
< tr style =cursor:pointer;类= TdBold >
< td onclick =FlipSec('edClg3')> Unit< / td>
< / tr>
< tr>
< td>< table id =edClg3runat =server>
< tr Ident =10style =cursor:pointer; width =100%class =TdBold>
< td width =10px>< input name =_ ctl6type =checkboxIDENT =10ID =10CType =0runat =serveronclick = CClick(事件)/>< / td>
< td onclick =FlipSec('edClg10')>< / td>
< td> College< / td>
< / tr>
< tr>
< td>< table id =edClg10runat =serverwidth =100%>
tr Ident =1002style =cursor:pointer; width =100%class =TdBold>
< td width =10px>< input name =_ ctl13type =checkboxIDENT =1002ID =1002CType =0runat =serveronclick = CClick(事件)/>< / td>
td onclick =FlipSec('edClg1002')> < / TD>
td> Department< / td>
< / tr>
< / tr>
< tr>
< td>< / td>
< tr>
< td>
< table id =edClg4>
< tr>
< td>
< pre>< td width =10px>< input name =_ ctl13type =checkboxIDENT =1002ID =1002CType =0runat =server onclick =CClick(event)/>< / td>
。
< / table>
< / table>
Hi all 这篇关于在嵌套表中查找HTML控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
,....
如何找到Checkbox在内表?
我尝试过:
< pre lang =c#> for ( int i = 0 ; i< List.Count; i ++)
{
Chk =(HtmlInputCheckBox) this .edList.FindControl(List [I]的ToString());
if (Chk!= null )
Chk.Checked = 真跨度>;
} 您生成的标记违反了HTML规则之一 - ID必须是唯一的...
您没有告诉我们List [i]是什么,但如果它是ID,则FindControl将在重复的情况下返回null ...
这个可以帮助您理解嵌套结构和FindControl的某些方面:了解ASP.NET模板 [ ^ ]
I write code that generates dynamically tables, as output :
<table id="edList" dir="rtl" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr style="cursor:pointer;" class="TdBold">
<td onclick="FlipSec('edClg3')">Unit </td>
</tr>
<tr>
<td><table id="edClg3" runat="server">
<tr Ident="10" style="cursor:pointer;" width="100%" class="TdBold">
<td width="10px"><input name="_ctl6" type="checkbox" IDENT="10" ID="10" CType="0" runat="server" onclick="CClick(event)" /></td>
<td onclick="FlipSec('edClg10')"></td>
<td>College</td>
</tr>
<tr>
<td><table id="edClg10" runat="server" width="100%">
tr Ident="1002" style="cursor:pointer;" width="100%" class="TdBold">
<td width="10px"><input name="_ctl13" type="checkbox" IDENT="1002" ID="1002" CType="0" runat="server" onclick="CClick(event)" /></td>
td onclick="FlipSec('edClg1002')"> </td>
td>Department</td>
</tr>
</tr>
<tr>
<td></td>
<tr>
<td>
<table id="edClg4">
<tr>
<td>
<pre><td width="10px"><input name="_ctl13" type="checkbox" IDENT="1002" ID="1002" CType="0" runat="server" onclick="CClick(event)" /></td>
.
</table>
</table>
,....
how do I find Checkbox in the inner tables?
What I have tried:
for (int i = 0; i <List.Count; i++)
{
Chk = (HtmlInputCheckBox)this.edList.FindControl(List[i].ToString());
if (Chk != null)
Chk.Checked = true;
}
Your generated markup violates one of the rules of HTML - ID must be unique...
You do not tell us what List[i] is, but if it is the ID, than FindControl will return null in case of duplicates...
This one may help you understand some aspects of nested structures and FindControl: Understanding ASP.NET Templates[^]