ASP.NET 动态创建 HTMLTableColumns(标题)

标签 asp.net html

是否可以使用命名空间 System.Web.UI.HtmlControls 动态创建 html 表列 (< th> )?

最佳答案

试试这个:

HtmlTable table1 = new HtmlTable();

        // Set the table's formatting-related properties.
        table1.Border = 1;
        table1.CellPadding = 3;
        table1.CellSpacing = 3;
        table1.BorderColor = "red";

        // Start adding content to the table.
        HtmlTableRow row;
        HtmlTableCell cell;
        for (int i=1; i<=5; i++)
        {
                // Create a new row and set its background color.
                row = new HtmlTableRow();
                row.BgColor = (i%2==0 ? "lightyellow" : "lightcyan");
                for (int j=1; j<=4; j++)
                {
                        // Create a cell and set its text.
                        cell = new HtmlTableCell();
                        cell.InnerHtml = "Row: " + i.ToString()+ "<br />Cell: " + j.ToString();
                        // Add the cell to the current row.
                        row.Cells.Add(cell);
                }

                // Add the row to the table.
                table1.Rows.Add(row);
        }

        // Add the table to the page.
        this.Controls.Add(table1);

关于ASP.NET 动态创建 HTMLTableColumns(标题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3394091/

相关文章:

html - ASP :TextBox with TextMode ="MultiLine" Wrap ="True" will not wrap

javascript - 带有 ClientValidationFunction 的 ASP.NET CustomValidator

asp.net - *ngFor 未显示任何记录

html - Shiny 的应用程序 - 单击新选项卡后,该选项卡仍由浏览器选中

java - 使用 JSoup 设置 HTML 标签的属性

javascript - 如何使用 knockout 单击按钮时从多个文本区域和单选按钮获取输入?

c# - ASP.NET 中的并发线程和锁

javascript - 尽管我的页面在浏览器中溢出但滚动条不起作用

HTML CSS 轮播主页

c# - 如何使用网络浏览器控件在弹出窗口中提供用户名和密码