zoukankan      html  css  js  c++  java
  • 如何遍历出一个页面中某个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;
                }
            }
        }
    }
  • 相关阅读:
    Python笔记17(Django之路由系统)
    Python笔记16(Django介绍与安装)
    Python笔记16(Web框架本质)
    序列的区间操作
    并查集(入门)
    (补题 Uva 3027)Corporative Network
    (补题 cf 1167C)News Distribution
    (补题 CF 1013B 模拟)And
    (补题 CF 1234C)Pipes
    (补题 POJ 1679 次小生成树)The Unique MST
  • 原文地址:https://www.cnblogs.com/wangfengderizi/p/2863117.html
Copyright © 2011-2022 走看看