日期:2014-05-17  浏览次数:20454 次

遍历查找控件问题
如下代码
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