stc*_*flw 1 c# asp.net algorithm performance rendering
我有一个20.000行和15列的DataTable.我需要创建一个ASP.Net表,我的代码与此类似:
//foreach Row in my DataTable do the following:
TableRow t2Row = new TableRow();
TableCell t2Cell0 = new TableCell(); t2Cell0.Text = Count.ToString(); t2Row.Cells.Add(t2Cell0);
TableCell t2Cell1 = new TableCell(); t2Cell1.Text = dr["col1"].ToString(); t2Row.Cells.Add(t2Cell1);
TableCell t2Cell3 = new TableCell(); t2Cell3.Text = dr["col2"].ToString(); t2Row.Cells.Add(t2Cell3);
TableCell t2Cell2 = new TableCell(); t2Cell2.Text = dr["col3"].ToString(); t2Row.Cells.Add(t2Cell2);
TableCell t2Cell4 = new TableCell(); t2Cell4.Text = dr["col4"].ToString(); t2Row.Cells.Add(t2Cell4);
TableCell t2Cell5 = new TableCell(); t2Cell5.Text = ""; t2Row.Cells.Add(t2Cell5);
t2Cell5.ColumnSpan = 4;
TableCell t2Cell9 = new TableCell(); t2Cell9.Text = convertMinToTime(dr["col6"].ToString(), dr["col7"].ToString()); t2Row.Cells.Add(t2Cell9);
TableCell t2Cell10 = new TableCell(); t2Cell10.Text = dr["col8"].ToString(); t2Row.Cells.Add(t2Cell10);
TableCell t2Cell11 = new TableCell(); t2Cell11.Text = dr["col9"].ToString(); t2Row.Cells.Add(t2Cell11);
TableCell t2Cell12 = new TableCell(); t2Cell12.Text = dr["col10"].ToString(); t2Row.Cells.Add(t2Cell12);
TableCell t2Cell13 = new TableCell(); t2Cell13.Text = dr["col11"].ToString(); t2Row.Cells.Add(t2Cell13);
Table my_Table= new Table();
my_Table.Rows.Add(t2Row);
Run Code Online (Sandbox Code Playgroud)
这段代码工作得很慢,有没有办法加快这个?
您可以使用Repeater并在ItemTemplate中添加<tr>
必要<td>
的.
首先检查是否真的是占用大量时间的表的构建.我的猜测是,对于一个包含20.000行和15列的表来说,传输和呈现HTML代码会降低速度.
归档时间: |
|
查看次数: |
1282 次 |
最近记录: |