您的位置:首页 > Web前端 > HTML

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

2010-03-18 23:32 507 查看
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);
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: