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;
                }
            }
        }
    }
  • 相关阅读:
    字符串常量池
    JDK1.8-java.lang.Object类源码阅读
    请给你的Mysql(InnoDB)表加上主键吧
    java线程占多大的内存,占哪里的内存?
    c# 多线程
    c# 遍历文件夹及其所有文件
    T-SQL 查询语句总结
    SQL Server使用LIKE运算符进行匹配查询
    sql server中关于批处理与脚本的简单介绍
    关于SQL Server数据表的五中约束
  • 原文地址:https://www.cnblogs.com/wangfengderizi/p/2863117.html
Copyright © 2011-2022 走看看