如何遍历出一个页面中某个TABLE中TEXTBOX的值?

如果是服务器端,需要先把Table转换为服务器端控件。
前台html:
<table style="100%;" id="table1" runat="server">
    <tr>
        <td>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <br />
            <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <br />
            <asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
        </td>
    </tr>
</table>

后台cs:
for (int i = 0; i < table1.Rows.Count; i++)
{
    System.Web.UI.HtmlControls.HtmlTableRow row = table1.Rows[i];
    for (int j = 0; j < row.Cells.Count; j++)
    {
        System.Web.UI.HtmlControls.HtmlTableCell cell = row.Cells[j];
        for (int k = 0; k < cell.Controls.Count; k++)
        {
            if (cell.Controls[k].GetType() == typeof(TextBox))
            {
                //获取到TextBox
                TextBox txt = cell.Controls[k] as TextBox;
                txt.Text = txt.ID;
            }
        }
    }
}
原文地址:https://www.cnblogs.com/wangfengderizi/p/2863117.html