Asp.net 为什么FindControl可以找到一个不';是否不属于当前表行?
我有一张桌子。我需要找到表中的所有DropDownList控件。我编写了以下代码来迭代表行以查找DropDownList控件。为什么在每个循环中,我都能找到DropDownList,即使我只有第4行的onAsp.net 为什么FindControl可以找到一个不';是否不属于当前表行?,asp.net,html-table,row,findcontrol,Asp.net,Html Table,Row,Findcontrol,我有一张桌子。我需要找到表中的所有DropDownList控件。我编写了以下代码来迭代表行以查找DropDownList控件。为什么在每个循环中,我都能找到DropDownList,即使我只有第4行的on for (int i = 0; i < table1.Rows.Count; i++) { foreach (string UserID in UserIDs)
for (int i = 0; i < table1.Rows.Count; i++)
{
foreach (string UserID in UserIDs)
{
string ddlID = "ddlEditings" + UserID;
DropDownList ddl = (DropDownList)table1.Rows[i].FindControl(ddlID);
if (ddl != null)
{
if (!updateableUsers.ContainsKey(Int32.Parse(UserID)))
updateableUsers.Add(Int32.Parse(UserID), Int32.Parse(ddl.SelectedValue));
}
}
}
for(int i=0;i
加价
<table id="ctl00_ContentPlaceHolder1_table1" border="1" width="100%">
<tr>
<td align="center" width="100%" colspan="3" bgcolor="#C0C0C0"><br /></td>
</tr>
<tr>
<td align="center" width="7%" bgcolor="#C0C0C0"></td>
<td align="center" width="50%" bgcolor="#CCE6FF">User Name</td>
<td align="center" width="43%" bgcolor="#CCE6FF">Editing Privileges</td>
</tr>
<tr>
<td align="center" width="7%" bgcolor="#C0C0C0"></td>
<td width="50%" bgcolor="#CCE6FF">Ferguson, Gene</td>
<td align="left" width="43%" bgcolor="#CCE6FF">functional manager</td>
</tr>
<tr>
<td align="center" width="7%" bgcolor="#C0C0C0"><input type="submit" name="ctl00$ContentPlaceHolder1$btnDelete5439" value="Delete" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$btnDelete5439", "", true, "", "", false, false))" id="ctl00_ContentPlaceHolder1_btnDelete5439" /></td>
<td width="50%" bgcolor="#CCE6FF">Lento, Jackie</td>
<td align="left" width="43%" bgcolor="#CCE6FF"><select name="ctl00$ContentPlaceHolder1$ddlEditings5439" id="ctl00_ContentPlaceHolder1_ddlEditings5439">
<option selected="selected" value="2">comments only</option>
<option value="1">view</option>
</select></td>
</tr>
<tr bgcolor="#C0C0C0">
<td width="100%" align="center" colspan="3"><input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Update" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$btnSubmit", "", true, "", "", false, false))" id="ctl00_ContentPlaceHolder1_btnSubmit" /><input type="submit" name="ctl00$ContentPlaceHolder1$btnReset" value="Reset" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$btnReset", "", true, "", "", false, false))" id="ctl00_ContentPlaceHolder1_btnReset" /><br /></td>
</tr>
</table>
用户名
编辑权限
弗格森,吉恩
职能经理
兰托,杰基
仅限评论
看法
您可以这样做。。。要查找html表中的所有控件
foreach(HtmlTableRow tr in Table1.Rows)
{
foreach(HtmlTableCell td in tr.Cells)
{
foreach(Control c in td.Controls)
{
Response.Write(c.ID);
}
}
}
是否可以包含表的标记(而不是输出)?顺便说一句,此表是动态创建的。如果是动态的,请包含生成表的代码。