protected void Page_Load(object sender, EventArgs e) { if (Cache["customerInfo"] == null) { customerBll customerBll = new customerBll(); Cache.Insert("customerInfo", customerBll.GetAllCustomerInfo(), null, DateTime.Now.AddSeconds(3), TimeSpan.Zero, CacheItemPriority.Normal, RemoveCacheItem); Response.Write("来自数据库的数据"); } else { Response.Write("来缓存"); //DataTable dt = (DataTable) Cache["customerInfo"]; } }
protected void Page_Load(object sender, EventArgs e) { customerBll customerBll = new customerBll(); DataTable dt = customerBll.GetAllCustomerInfo(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < dt.Rows.Count; i++) { sb.AppendFormat("<tr><td>{0}</td>" + "<td>{1}</td>" + "<td>{2}</td>" + "<td><a href = \"DeleteCustomer.ashx?id={3}\" class = \"delete\">删除</a></td>" + "<td><a href = EditCustomer.aspx?id={4} class = edit>修改</a></td>" + "</tr></br>", dt.Rows[i]["ID"], dt.Rows[i]["Name"], dt.Rows[i]["Age"], dt.Rows[i]["ID"], dt.Rows[i]["ID"]); } strHtml = sb.ToString(); }