Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
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:

C#
for (int i = 0; i <List.Count; i++)
{
     Chk = (HtmlInputCheckBox)this.edList.FindControl(List[i].ToString());
     if (Chk != null)
         Chk.Checked = true;
}
Posted
Updated 6-May-18 10:01am
v3
Comments
Krunal Rohit 6-May-18 1:53am    
If you're generating this dynamic tables, then generate them with proper ID.
That way you'll have access of them later.

KR

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900