CSDN博客

img IsEOF

应用C# 可变数量的参数,使Tabel 随意显示

发表于2004/7/7 17:46:00  1022人阅读

为了使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); 
   }
  }

我的效果图:

0 0

相关博文

我的热门文章

img
取 消
img