即使不分页,只要页面生成后,再后台重新载入不同的数据,记录略多(》30),就很慢了。后台数据生成只用时2毫秒,可是到前台显示,就要6秒以上,
看示例:后台代码很简单。就是生成不同记录数记录。
- protected void GetDataTableAll(int RecCount)
- {
- DateTime dt1 = DateTime.Now;
- DataTable table = new DataTable();
- table.Columns.Add(new DataColumn("Id", typeof(int)));
- table.Columns.Add(new DataColumn("Name", typeof(String)));
- table.Columns.Add(new DataColumn("Major", typeof(String)));
- DataRow row = null;
- for (int i = 0; i < RecCount; i++)
- {
- row = table.NewRow();
- row[0] = i;
- row[1] = "这是" + RecCount + "条数据";
- row[2] = "计算机应用技术";
- table.Rows.Add(row);
- }
- Grid1.DataSource = table;
- Grid1.DataBind();
- TimeSpan ts = DateTime.Now - dt1;
- labTs.Text = "后台数据生成用时:" + ts.TotalMilliseconds.ToString() + "毫秒";
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- GetDataTableAll(10);
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- GetDataTableAll(100);
- }
- protected void Button3_Click(object sender, EventArgs e)
- {
- GetDataTableAll(50);
- }
复制代码
|