日期:2014-05-20 浏览次数:20813 次
protected void Page_Load(object sender, EventArgs e) { long recordCount, pageCount; var paged = GetData(30, p,x=>true, x => x.id, out recordCount, out pageCount); d1 = DateTime.Now; list.DataSource = paged; list.DataBind(); Response.Write("计时:" + (DateTime.Now - d1).TotalMilliseconds + "ms<br />"); } private IQueryable<kaoqin_bak> GetData( int _pageSize, int _pageIndex, Func<kaoqin_bak,bool> where, Func<kaoqin_bak, int> order, out long _recordCount, out long _pageCount) { KaoQinDataContext db = new KaoQinDataContext(); var paged = (from x in db.kaoqin_bak select x) .Where(where) .OrderByDescending(order) .Skip((_pageIndex - 1) * _pageSize) .Take(_pageSize).AsQueryable(); _recordCount = (from p in db.kaoqin_bak select p.id).LongCount(); _pageCount = _recordCount / _pageSize; return paged; }
…… var paged = GetData(30, p, out recordCount, out pageCount); …… private IQueryable<kaoqin_bak> GetData( int _pageSize, int _pageIndex, out long _recordCount, out long _pageCount) { KaoQinDataContext db = new KaoQinDataContext(); var paged = (from x in db.kaoqin_bak select x) .Where(x=>true) .OrderByDescending(x=>x.id) .Skip((_pageIndex - 1) * _pageSize) .Take(_pageSize).AsQueryable(); _recordCount = (from p in db.kaoqin_bak select p.id).LongCount(); _pageCount = _recordCount / _pageSize; return paged; }