为了使ASP.net 的Table控件能够显示更为复杂的报表,由于比较复杂的报表,列的个数比较随意,于是想到了C#的 params :
//在Table插入一行,列数及列跨的行数
private void ReportTable(Table table,Color bkclr,Color fclr,HorizontalAlign ha,int ColumnSpan,params string [] Columns)
{
TableRow r = new TableRow();
TableCell c ;
foreach(string Column in Columns)
{
c = new TableCell();
c.Text = Column;
c.HorizontalAlign =ha;
c.Wrap = false;
c.ForeColor = fclr;
c.BackColor = bkclr;
c.ColumnSpan = ColumnSpan;
r.Cells.Add(c);
}
table.Rows.Add(r);
}
//在nRow 行插入列数!
private void RowFollow(Table table,int nRow,Color bkclr,Color fclr,HorizontalAlign ha,int ColumnSpan,params string [] Columns)
{
TableCell c ;
int index=0;
foreach(string Column in Columns)
{
index = table.Rows[nRow].Cells.Count;
c = new TableCell();
c.Text = Column;
c.HorizontalAlign =ha;
c.Wrap = false;
c.ForeColor = fclr;
c.BackColor = bkclr;
c.ColumnSpan = ColumnSpan;
table.Rows[nRow].Cells.AddAt(index,c);
}
}
我的效果图: