首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

遍历查找控件有关问题

2012-09-10 
遍历查找控件问题如下代码C# code tr idtrDinner runatservertd alignright classtablebk2

遍历查找控件问题
如下代码

C# code
 <tr id="trDinner" runat="server">                        <td align="right" class="tablebk2" width="12%">                            <asp:Label ID="lblMainDeskNumber" runat="server" Text="主桌人数"></asp:Label>                        </td>                        <td align="left" class="tablebk3" width="38%">                            <asp:Label ID="lblMainHostGov" runat="server" Text=" 主方政府"></asp:Label>                            <asp:TextBox ID="txtMainHostGov" runat="server" Width="30"></asp:TextBox>                            <asp:Label ID="lblMainGuestGov" runat="server" Text="客方政府"></asp:Label>                            <asp:TextBox ID="txtMainGuestGov" runat="server" Width="30"></asp:TextBox><br runat="server"                                id="br1" />                            <asp:Label ID="lblMainHostCompany" runat="server" Text=" 主方企业"></asp:Label>                            <asp:TextBox ID="txtMainHostCompany" runat="server" Width="30"></asp:TextBox>                            <asp:Label ID="lblMainGuestCompany" runat="server" Text="客方企业"></asp:Label>                            <asp:TextBox ID="txtMainGuestCompany" runat="server" Width="30"></asp:TextBox></td>                        <td align="right" class="tablebk2" width="12%">                            <asp:Label ID="lblBranchDesNumber" runat="server" Text="副桌人数"></asp:Label>                        </td>                        <td align="left" class="tablebk3" width="38%">                            <asp:Label ID="lblBranchHostGov" runat="server" Text="主方政府"></asp:Label>                            <asp:TextBox ID="txtBranchHostGov" runat="server" Width="30"></asp:TextBox>                            <asp:Label ID="lblBranchGuestGov" runat="server" Text="客方政府"></asp:Label>                            <asp:TextBox ID="txtBranchGuestGov" runat="server" Width="30"></asp:TextBox><br runat="server"                                id="br2" />                            <asp:Label ID="lblBranchHostCompany" runat="server" Text=" 主方企业"></asp:Label>                            <asp:TextBox ID="txtBranchHostCompany" runat="server" Width="30"></asp:TextBox>                            <asp:Label ID="lblBranchGuestCompany" runat="server" Text="客方企业"></asp:Label>                            <asp:TextBox ID="txtBranchGuestCompany" runat="server" Width="30"></asp:TextBox></td>                    </tr>

需求:我要遍历trDinner下的所有textbox,因为trDinner是table的行,所以我用this.trDinner.Controls遍历不到TextBox
求指导

[解决办法]
var m = this.form1.FindControl("trDinner");
foreach (Control c in m.Controls)
{
if(c.GetType().Name=="TextBox")
Response.Write(((TextBox)c).ID);
}
试试这个
------解决方案--------------------


把td也换成服务器端。。。或者把tr变为客户端控件

tr里面的控件不是动态添加吧?不是的话 循环页面所有控件,选择符合条件的

热点排行