要在GridView中加入

//实现分页

AllowPaging="true"

//一页数据10行

PageSize="10"

// 分页时触发的事件 OnPageIndexChanging="gvwDesignationName_PageIndexChanging"

在服务器事件里

protectedvoid gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e) { 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 protectedvoid 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分页的实现的更多相关文章

  1. asp.net gridview 分页显示不出来的问题

    使用gridview分页显示,在点击第二页的时候显示空白,无数据. 原因是页面刷新,绑定datatable未执行 解决方法: 1.将datatable设置为静态 2.在OnPageIndexChang ...

  2. Android GridView 分页加载数据

    android UI 往右滑动,滑动到最后一页就自动加载数据并显示 如图: package cn.anycall.ju; import java.util.ArrayList; import java ...

  3. GridView 分页方法

    要实现GrdView分页的功能. 操作如下: 1.更改GrdView控件的AllowPaging属性为true. 2.更改GrdView控件的PageSize属性为 任意数值(默认为10) 3.更改G ...

  4. GridView分页排序

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewPage.asp ...

  5. GridView分页功能的实现

    当GridView中显示的记录很多的时候,可以通过GridView的分页功能来分页显示这些记录.如果GridView是直接绑定数据库,则很简单:将"启动分页"打勾即可. 如果是用代 ...

  6. GridView分页的实现 ASP.NET c#(转)特好用

    要在GridView中加入 //实现分页 AllowPaging="true" //一页数据10行 PageSize="10" // 分页时触发的事件OnPag ...

  7. 自己写的一个ASP.NET服务器控件Repeater和GridView分页类

    不墨迹,直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  8. GridView分页操作

    1.html <PagerStyle HorizontalAlign="Center" /> <PagerTemplate> 第: <asp:Labe ...

  9. gridview分页

    protected void lnkbtnFrist_Click(object sender, EventArgs e) { //首页 ; this.ReadData(); } protected v ...

随机推荐

  1. 【HDOJ】1031 Design T-Shirt

    qsort直接排序. #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN ...

  2. Automatic Code Generation-->Implement Interface

    https://msdn.microsoft.com/en-us/library/hk90416s(v=vs.110).aspx VS中自带的只能提示,一个类继承自某一个接口. 由VS为类生成接口所要 ...

  3. [ZOJ 3622] Magic Number

    Magic Number Time Limit: 2 Seconds      Memory Limit: 32768 KB A positive number y is called magic n ...

  4. 【转】我的电脑最近忽然开不了机,启动修复也无法修复,win7系统。开机的时候如果不点启动修复直接正常启动

    原文网址:http://wenda.haosou.com/q/1356139178064356 你好,电脑开机蓝屏主要是:“磁盘有错误”或“非正常关机”引起!这是解决方法:(原创,引用请说明作者:力王 ...

  5. 如何区分Shapefile,Coverage,Geodatabase(转载)

    转自:http://www.cnblogs.com/linhugh/archive/2012/04/06/2435266.html 在过去20年中,矢量数据模型是GIS中变化最大的方面,例如,ESRI ...

  6. 使用jQuery实现简单的拖动效果

    转自:http://www.muzilei.com/archives/136 如何实现拖动效果? 浏览DEMO 首先分析下拖动效果原理: 1.当鼠标在被拖动对象上按下鼠标(触发onmousedown事 ...

  7. 关于.NET三层 分类: C#

    三层体系结构的概念 用户界面表示层(USL) 业务逻辑层(BLL) 数据访问层(DAL) BLL将USL与DAL隔开了,并且加入了业务规则 各层的作用 1:数据数据访问层:主要是对原始数据(数据库或者 ...

  8. RedHat/CentOS系统信息查看命令大全

    系统# uname -a               # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue   # 查看操作系统版本# cat /proc/cpuinfo   ...

  9. 哈希(3) java中的hashcode

    看看jdk api中对object类的描述 1.http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html 2首先你要知道每个对象都有 ...

  10. HTTPS、SSL与数字证书介绍

    在互联网安全通信方式上,目前用的最多的就是https配合ssl和数字证书来保证传输和认证安全了.本文追本溯源围绕这个模式谈一谈. 名词解释 HTTPS:在HTTP(超文本传输协议)基础上提出的一种安全 ...