AspNetPager控件使用
来源:互联网 发布:中航资本股东数据 编辑:程序博客网 时间:2024/05/18 03:45
不同于DataGrid控件,AspNetPager分页控件本身并不显示任何数据,而只显示页导航元素,数据在页面上的显示方式与该控件无关。该控件可以为DataGrid、DataList、Repeater以及自定义控件进行分页,配合Sql存储过程,分页性能较使用DataGrid分页有明显提升,尤其是当数据量大时性能可提升数倍!
AspNetPager 2.0 中新增了通过Url来分页的功能,这使得访问者可以直接输入相应的Url来访问任何页面,并且搜索引擎也可以直接检索每个页面,若使用DataGrid的分页功能,这是无法实现的。
要使用 AspNetPager 分页控件,必须最少指定它的 RecordCount 属性,指定并编写 PageChanged 事件的处理程序。 RecordCount 属性指定要分页的所有数据的总项数,若未指定该值或该值小于等于 PageSize ,则AspNetPager控件不会显示任何内容。 若未指定并编写 PageChanged 事件处理程序,则当用户点击页导航元素或在页索引文本框中手式输入页索引并提交时AspNetPager不会跳转到指定的页。 AspNetPager控件的分页方法和DataGrid基本相同,即在它的 PageChanged 事件处理程序中将传递事件数据的 PageChangedEventArgs 的 NewPageIndex值赋给 AspNetPager的 CurrentPageIndex属性,然后重新将新的数据与数据显示控件绑定。
RecordCount :当页面第一次加载时,应以编程方式将从存储过程或Sql语句中返回的数据表中所有要分页的记录的总数赋予该属性,AspNetPager会将其保存的ViewState中并在页面回发时从ViewState中获取该值,因此避免了每次分页都要访问数据库而影响分页性能。AspNetPager根据要分页的所有数据的总项数和 PageSize 属性来计算显示所有数据需要的总页数,即 PageCount的值。
PageSize :该值获取或设置数据呈现控件每次要显示数据表中的的数据的项数,AspNetPager根据该值和 RecordCount 来计算显示所有数据需要的总页数,即 PageCount的值
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<webdiyer:AspNetPager ID="_pager" runat="server"
CurrentPageButtonPosition="Center"
CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条"
FirstPageText="首页" HorizontalAlign="Right" LastPageText="尾页" NextPageText="下一页"
PrevPageText="上一页" ShowCustomInfoSection="Right" UrlPaging="True" Width="80%"
Wrap="False" PagingButtonSpacing="8px" onpagechanged="_pager_PageChanged"
PageSize="9">
</webdiyer:AspNetPager>
private void Bind()
{
int size = _pager.PageSize;
int start = _pager.PageSize * (_pager.CurrentPageIndex - 1);
string name = "";
int typeID = 0;
if (Request.QueryString["name"] != null)
name = Request.QueryString["name"].ToString();
if (Request.QueryString["typeID"] != null)
typeID = Convert.ToInt32(Request.QueryString["typeID"].ToString());
ProductManager pm = new ProductManager();
_pager.RecordCount = pm.GetCount(name, typeID, null, null);
_dlProduct.DataSource = pm.GetAllProduct(name, typeID,start,size,null,name);
_dlProduct.DataBind();
}
protected void _pager_PageChanged(object sender, EventArgs e)
{
Bind();
}
- AspNetPager控件一点使用
- AspNetPager分页控件使用
- AspNetPager控件的使用
- aspnetpager控件使用
- AspNetPager控件使用
- Aspnetpager控件的使用
- 使用AspNetPager控件分页
- 使用AspNetPager控件分页
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspnetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- Repeater使用 AspNetPager分页控件
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- 结合UIImageView实现图片的移动和缩放
- 检测点1.1
- StarUML 学习
- Android开发进阶之NIO非阻塞包(五)
- wcf简单使用小结
- AspNetPager控件使用
- [B14237-04]Oracle® Database Reference 10g Release 2 (10.2)
- Java EE集群技术初探
- 帖子
- JAVA DOC注释模版设置
- Linux 进程管理
- Apache无法启动解决 the requested operation has failed
- Android开发进阶之NIO非阻塞包(六)
- Android开发进阶之NIO非阻塞包(七)