AspNetPager分页实际应用
2014-05-12 08:55
381 查看
---恢复内容开始---
首先,这个分页是快速开发的一种,弊端就是一次查询数据库全部,然后分页显示.
注意:
1,最好绑定的数据是一个list格式!
1首先打开
http://www.webdiyer.com下载AspNetPager
然后引用这个dll文件
然后在aspx前台最上面引用该dll
2在展示数据用的一些控件下面复制上
3在后台要写上这样一个方法
4
前台索引自增排序这样写
倒序排序这样写
首先,这个分页是快速开发的一种,弊端就是一次查询数据库全部,然后分页显示.
注意:
1,最好绑定的数据是一个list格式!
1首先打开
然后引用这个dll文件
然后在aspx前台最上面引用该dll
<%@RegisterAssembly="AspNetPager"Namespace="Wuqi.Webdiyer"TagPrefix="webdiyer"%>
2在展示数据用的一些控件下面复制上
<webdiyer:AspNetPagerID="AspNetPager1"runat="server"FirstPageText="首页"LastPageText="最后一页" NextPageText="下一页"PrevPageText="上一页"OnPageChanged="AspNetPager1_PageChanged" Font-Size="X-Large"ForeColor="#336699"HorizontalAlign="Center"> </webdiyer:AspNetPager>
3在后台要写上这样一个方法
protectedvoidAspNetPager1_PageChanged(objectsender,EventArgse) { BindDataTable(); }
4
BindDataTable();这个方法就是绑定数据的方法
privatevoidBindDataTable() { StringBuildersb=newStringBuilder(); //GetAllList是查询数据,返回的是DataSet格式的, DataSetds=bll.GetAllList(sb.ToString()); //计算总共有多少条 AspNetPager1.RecordCount=ds.Tables[0].Rows.Count; //每页显示多少条 AspNetPager1.PageSize=10; PagedDataSourcepds=newPagedDataSource(); pds.DataSource=ds.Tables[0].Rows.ToString(); pds.AllowCustomPaging=true; pds.AllowPaging=true; pds.CurrentPageIndex=AspNetPager1.CurrentPageIndex-1; pds.PageSize=AspNetPager1.PageSize; pagesize=AspNetPager1.PageSize; inti=(pds.CurrentPageIndex)*pds.PageSize; pageindex=pds.CurrentPageIndex; //这是创建一个实体类,来把DataSet格式转换list格式 List<ChaxunClass>list=newList<ChaxunClass>(); //遍历数据,已list格式输出 foreach(DataRowrowinds.Tables[0].Rows) { ChaxunClasscl=newChaxunClass(); cl.num=row["第三方卡"].ToString(); list.Add(cl); } this.Repeater1.DataSource=list.Skip((pds.CurrentPageIndex)*pds.PageSize).Take(pds.PageSize);; this.Repeater1.DataBind(); }
以上是最初的,后来研究下还是在这样方便,一个分页干吗要用2个控件 后台改成,
DataSetds=bll.GetAllList(sb.ToString()); intPageCount=AspNetPager1.RecordCount=ds.Tables[0].Rows.Count; pagesize=AspNetPager1.PageSize=10; pageindex=AspNetPager1.CurrentPageIndex; List<ChaxunClass>list=newList<ChaxunClass>(); foreach(DataRowrowinds.Tables[0].Rows) { ChaxunClasscl=newChaxunClass(); cl.num=row["第三方卡"].ToString(); list.Add(cl); } this.Repeater1.DataSource=list.Skip((pagesize)*(pageindex-1)).Take(pagesize); this.Repeater1.DataBind();
前台索引自增排序这样写
<%#(pageindex-1)*pagesize+Container.ItemIndex+1%>
倒序排序这样写
<%#(PageCount-(pageindex-1)*pagesize)-Container.ItemIndex%>
相关文章推荐
- AspNetPager分页控件的应用(二)
- AspNetPager分页控件应用实例
- asp.net aspnetpager分页统计时与实际不符的解决办法
- AspNetPager分页示例—应用CSS样式
- AspNetPager分页控件应用试例
- JavaScript实际应用:innerHTMl
- asp.net aspnetpager 应用
- Ruby元编程:动态添加类属性及其实际应用
- 常见算法在实际项目中的应用
- 分页控件AspNetPager的样式美化
- JavaScript实际应用:innerHTMl和确认提示的使用
- Intellij IDEA开发环境配置及实际开发应用
- 使用aop配置事务-实际应用
- Python中类和对象的实际应用
- 六.函数,动态sql,游标在实际中的应用
- JQuery分页插件bs_pagination的应用
- Redis在Php项目中的实际应用场景
- AspNetPager分页控件的使用
- jquery实际项目中的应用2