【代码示例】动态给HtmlTable添加行数据

来源:互联网 发布:入侵五角大楼的网络 编辑:程序博客网 时间:2024/05/01 17:28

DataTable tbReportInfo = gettable() // 查询出的数据源table

        foreach (DataRow row1 in tbReportInfo.Rows)
        {
            HtmlTableRow tr = new HtmlTableRow();
            foreach (DataColumn dc in tbReportInfo.Columns)
            {
                if (row1[dc.ColumnName.ToString()].ToString().Length == 0)
                {
                    addInfoToCell("0", tr);
                }
                else
                {
                    addInfoToCell(row1[dc.ColumnName.ToString()].ToString(), tr);
                }
            }
            tbxsDetail.Rows.Add((HtmlTableRow)tr);
        }
    }
    private void addInfoToCell(string info, HtmlTableRow tr)
    {
        HtmlTableCell tc = new HtmlTableCell();
        tc.Controls.Add(new LiteralControl(info));
        if (IsNumberic(tc.InnerText))
        {
            tc.Align = "right";
        }
        else
        {
            tc.Align = "left";
        }
        tc.InnerText = formatString(tc.InnerText);
        tr.Cells.Add(tc);
    }

原创粉丝点击