AspNetPager 与PagedDataSource 配合为GRIDVIEW控件分页
来源:互联网 发布:免费刷svip永久软件 编辑:程序博客网 时间:2024/06/05 16:57
原理:
1、不用反复读库,不用多次绑定
2、绑定一次,将结果存在页面缓存
首先在页面引入:<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
页面HTML代码
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CssClass="pages" CurrentPageButtonClass="currentpage" CustomInfoHTML="共%RecordCount%条,当前为第%CurrentPageIndex%页,共%PageCount%页" CustomInfoSectionWidth="40%" CustomInfoTextAlign="Left" HorizontalAlign="Right" NumericButtonCount="10" OnPageChanged="AspNetPager1_PageChanged" ShowBoxThreshold="10" ShowCustomInfoSection="Left" Visible="true" ShowFirstLast="false" ShowPageIndexBox="Never" Width="100%" PageSize="15"> </webdiyer:AspNetPager>
后台:
1、定义页面变量
public DataTable PageTable
{
get
{
return ViewState["PageTable"] != null ? (DataTable)ViewState["PageTable"] : null;
}
set
{
ViewState["PageTable"] = value;
}
}
2、将从数据库中读取的DataTable赋值给PageTable
即 PageTable=dt(从数据库读取的结果)
3.调用数据绑定方法 GridViewDataBound()
private void GridViewDataBound()
{
//初始化分页数据源实例
PagedDataSource pds = new PagedDataSource();
//设置总行数
AspNetPager1.RecordCount = PageTable.Rows.Count;
//设置分页的数据源
pds.DataSource = PageTable.DefaultView;
//设置当前页
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; //AspNetPager1是AspNetPager的ID
//设置每页显示页数
pds.PageSize = AspNetPager1.PageSize;
//启用分页
pds.AllowPaging = true;
//设置GridView的数据源为分页数据源
GV_TJData.DataSource = pds; //GV_TJData是绑定数据的GridView的ID
//绑定GridView
GV_TJData.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
GridViewDataBound();//当页码改变时,重新绑定GridView即可,不需要重新读取数据库
}
- AspNetPager 与PagedDataSource 配合为GRIDVIEW控件分页
- gridview分页控件aspnetpager用法
- LINQ + AspNetPager + GridView 分页控件
- .net分页控件webdiyer:aspnetpager与gridview联用
- (续篇).net分页控件webdiyer:aspnetpager与gridview联用
- (再续).net分页控件webdiyer:aspnetpager与gridview联用
- 数据空间配合aspnetpager分页控件试用
- 使用AspNetPager控件实现GridView分页
- 分页与查询 关于gridview 引入AspNetPager
- 使用AspNetPager与GridView完成分页
- 使用AspNetPager与GridView完成分页
- 使用AspNetPager与GridView完成分页
- 使用AspNetPager与GridView完成分页
- AspNetPager与gridview结合实现分页
- PagedDataSource实现分页datalist,gridview。。。
- GridView用PagedDataSource实现分页
- AspNetPager控件的分页与排序
- AspNetPager控件的分页与排序
- EBS预置文件作用收集整理
- java反射详解
- Ural 1277
- Android矩阵原理详解(Matrix,ColorMatrix)
- 单词数
- AspNetPager 与PagedDataSource 配合为GRIDVIEW控件分页
- Extracting Metada From Files
- 使用python编写脚本获取手机当前应用的信息
- 有关坐标系常见问题的问与答
- 修改select边框颜色 兼容ie
- 解决FAT32格式的U盘无法拷贝4G以上文件的方法
- web表单设计器Ueditor Formdesign Plugins安装使用教程
- 微信支付 JAVA实现
- 文本文件与二进制文件的编码差别