赞
踩
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); }