Apply C # variable number of parameters to make Tabel

zhaozj2021-02-12  148

In order to make ASP.NET's Table controls display more complex reports, the number of columns is relatively casual due to complicated reports, so I thought of C #'s params:

// Insert a line, the number of columns and columns of columns in 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);

// Insert the number of columns in the NROW line!

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

My rendering:

转载请注明原文地址:https://www.9cbs.com/read-6629.html

New Post(0)