要在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. 转:三十、Java图形化界面设计——布局管理器之BorderLayout(边界布局)

    http://blog.csdn.net/liujun13579/article/details/7772215 边界布局管理器把容器的的布局分为五个位置:CENTER.EAST.WEST.NORTH ...

  2. v8 javascript engine

    https://code.google.com/p/v8-wiki/wiki/BuildingWithGYP vs2013git v8 http://github.com/v8/v8-git-mirr ...

  3. VM Depot 助您使用本地开源软件架设开发 Web 站点

     发布于 2014-04-25 作者 云 浪生 使用 VM Depot 中的镜像在 Azure 上创建.开发.部署网站与应用不仅方便快捷而且省时省力!感谢开源社区的大力支持,我们的VM Depot ...

  4. 在 SharePoint 2010 中访问数据

    转:http://blog.banysky.net/?p=81001 数据访问的关键方法有哪些? | 使用查询类 | 使用 SPQuery | 使用 SPSiteDataQuery | 使用 LINQ ...

  5. Android-webView的loadUrl

    1 //打开本包内asset目次下的test.html文件 wView.loadUrl(" file:///android_asset/test.html "); 2 //打开本地 ...

  6. Linux无线网络设置(wpa_supplicant的使用)

    主机环境:Gentoo Linux 3.1.10 WPA Supplicant工具包可以让您连接到那些使用WPA的AP.因为还只是beta版,所以它的配置方法仍会常常变化——尽管如此,在大部分情况下它 ...

  7. Mac下快捷键列表

    主界面 command + tab 切换程序 command + ` 在程序内切换界面 command + w 关闭界面 command + q 关闭程序 command + option + esc ...

  8. JDBC_demo:java连接mysql过程

    1.任何数据库驱动程序都提供对java.sql.Driver接口的驱动类,mysql-connector-java-5.1.39-bin.jar中Driver: package com.mysql.j ...

  9. 5 个在 Linux 中管理文件类型和系统时间的有用命令

    对于想学习 Linux 的初学者来说要适应使用命令行或者终端可能非常困难.由于终端比图形用户界面程序更能帮助用户控制 Linux 系统,我们必须习惯在终端中运行命令.因此为了有效记忆 Linux 不同 ...

  10. 【转】如何实现一个malloc

    任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉.但是,许多程序员对malloc背后的事情并不熟悉,许多人甚至 ...