GridView分页的实现 ASP.NET c#(转)特好用
要在GridView中加入
//实现分页
AllowPaging="true"
//一页数据10行
PageSize="10"
// 分页时触发的事件
OnPageIndexChanging="gvwDesignationName_PageIndexChanging"
在服务器事件里

{
gvwDesignationName.PageIndex=e.newIndex;
bingDesignatioonName();
}

这里我给出一个通用显示分页的模板(网上搜的,自己给出注释)
Code
<PagerTemplate>
当前第:
//((GridView)Container.NamingContainer)就是为了得到当前的控件
<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
页/共:
//得到分页页面的总数
<asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
页
//如果该分页是首分页,那么该连接就不会显示了.同时对应了自带识别的命令参数CommandArgument
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页</asp:LinkButton>
//如果该分页是尾页,那么该连接就不会显示了
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页</asp:LinkButton>
转到第
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
//这里将CommandArgument即使点击该按钮e.newIndex 值为3
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"
CommandName="Page" Text="GO" />
</PagerTemplate>
对应该事件中代码为
Code
protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// 得到该控件
GridView theGrid = sender as GridView;
int newPageIndex = ;
if (e.NewPageIndex==-)
{
//点击了Go按钮
TextBox txtNewPageIndex = null; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
GridViewRow pagerRow = theGrid.BottomPagerRow;
if (pagerRow != null)
{
//得到text控件
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
}
if ( txtNewPageIndex!= null)
{
//得到索引
newPageIndex = int.Parse(txtNewPageIndex.Text) - ;
}
}
else
{
//点击了其他的按钮
newPageIndex = e.NewPageIndex;
}
//防止新索引溢出
newPageIndex = newPageIndex < ? : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - : newPageIndex;
//得到新的值
theGrid.PageIndex = newPageIndex;
//重新绑定
bingDesignatioonName();
}
GridView分页的实现 ASP.NET c#(转)特好用的更多相关文章
- asp.net gridview 分页显示不出来的问题
使用gridview分页显示,在点击第二页的时候显示空白,无数据. 原因是页面刷新,绑定datatable未执行 解决方法: 1.将datatable设置为静态 2.在OnPageIndexChang ...
- GridView分页的实现
要在GridView中加入 //实现分页 AllowPaging="true" //一页数据10行 PageSize="10" // 分页时触发的事件 OnPa ...
- GridView分页操作
1.html <PagerStyle HorizontalAlign="Center" /> <PagerTemplate> 第: <asp:Labe ...
- Android GridView 分页加载数据
android UI 往右滑动,滑动到最后一页就自动加载数据并显示 如图: package cn.anycall.ju; import java.util.ArrayList; import java ...
- 自己写的一个ASP.NET服务器控件Repeater和GridView分页类
不墨迹,直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- GridView 分页方法
要实现GrdView分页的功能. 操作如下: 1.更改GrdView控件的AllowPaging属性为true. 2.更改GrdView控件的PageSize属性为 任意数值(默认为10) 3.更改G ...
- GridView分页排序
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewPage.asp ...
- 分页控件-ASP.NET(AspNetPager)
AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: <div class="oa-el ...
- GridView分页功能的实现
当GridView中显示的记录很多的时候,可以通过GridView的分页功能来分页显示这些记录.如果GridView是直接绑定数据库,则很简单:将"启动分页"打勾即可. 如果是用代 ...
随机推荐
- [datatable]排序时指定某列不可排序
datatable是一个jquery扩展的表格插件.其提供了强大的表格功能. 官方地址:http://www.datatables.net/ 在官方示例中,对于表格的是否可排序是在初始化中设置的一个值 ...
- Android 沉浸式顶部
研究了下这个,记录下代码. 主页面代码:activity_main.xml <?xml version="1.0" encoding="utf-8"?&g ...
- [转]mybatis if test非空判断数字0为什么是false
原文地址:http://blog.51cto.com/wangguangshuo/1944531 今天工作中发现一个Long类型的参数没有传到sql中去,在sql xml配置文件中是使用if test ...
- Vagrant (3) —— 复制/备份Vagrant Box
Vagrant (3) -- 复制/备份Vagrant Box 摘要 介绍复制/备份Vagrant Box基本方法 版本 Vagrant版本: 1.8.1 内容 复制vagrant box并压缩 关闭 ...
- 12 extremely useful hacks for JavaScript
In this post I will share 12 extremely useful hacks for JavaScript. These hacks reduce the code and ...
- Reading and writing RData files
前面添加个lapply()或者dplyr::llply()就能读取,储存多个文件了.http://bluemountaincapital.github.io/FSharpRProvider/readi ...
- mysql游标的使用
这是一个游标的使用例子. 但是其中有几点需要注意,就是为什么要加入 declare CONTINUE HANDLER FOR SQLSTATE '02000' SET tmpname = null;这 ...
- oozie 入门
转自:http://blackproof.iteye.com/blog/1928122 oozie概述:oozie能干什么 oozie格式:怎么用oozie oozie执行:怎么运行oozie ooz ...
- 《FPGA全程进阶---实战演练》第十二章 二进制码与格雷码PK
大家在写程序的时候,可能会听闻,什么独热码,什么格雷码,什么二进制码等等,本节意在解释这几种编码之间的区别和优势以及用verilog怎么去实现,下面先介绍这几种编码的区别. 1 基础理论部分 1.1 ...
- Mac下Pycharm导入Python包
1.png 2.png 3.png