关于高效分页: 1、在DAL层中编辑两个方法:得到所有行数据,获得分页数据 public int GetCount() { string sql="select count(*) from photos"; DataTable dt=SqlHelper.GetTable(sql); return Convert.ToInt32(dt.Rows[0][0]); } //startRowIndex开始行 和总行数 public List GetPagePhotos(int startRowIndex,int maxRow) { sql="select * from (select *,row_number() over(order by pid) as num from photos) as t where t.num>@start and t.num<=@start and t.num<=@start+@max"; SqlParameter[] param={ new SqlParameter("@start",startRowIndex), new SqlPatameter("@max",maxRow) }; List photos=new List(); DataTable dt=SqlHelper.GetTable(sql,param); foreach(DataRow dr in dt.Rows) { Photos p=RowAllPhotos(dr); photos.Add(p); } return photos; } 2.在BLL中调用 public int GetCount() { return dal.GetCount(); } public List GetPagePhotos(int startRowIndex,int maxRow) { return dal.GetPagePhotos(startRowIndex,maxRow); } 3、在UI层中设置Listview,获取的数据源为GetPagePhotos.并删除自动生成的这两个参数的方法、 设置ObjectDataSource中有关分页的几个参数: EnablePaging:True MaximumRowsParameterName:maxRow SelectCountMethod:GetCount StartRowIndexParameterName:startRowIndex 4、本身Listview是不能实现分页的,这要借助专门的分页控件:DataPage来实现 设置DataPage中的几个参数: PageControlID:ListView1 这个是指明为哪一个ListView分页 PageSize:3 每页要显示的行数 QueryStringField:Page 这个是用来在QueryString中显示第几页,方便查找
posted on 2012-08-27 02:24  Fan帥帥  阅读(164)  评论(0编辑  收藏  举报