要在GridView中加入//实现分页

AllowPaging="true" PageSize="10"

// 分页时触发的事件
protectedvoid gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gvwDesignationName.PageIndex=e.newIndex;
    bingDesignatioonName();
}

这里我给出一个通用显示分页的模板(网上搜的,自己给出注释)

对应该事件中代码为

<PagerTemplate>

当Ì¡À前¡ã第̨²:

<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1
%>"></asp:Label>

页°3/共2:

<asp:Label ID="LabelPageCount" runat="server" Text="<%#
((GridView)Container.NamingContainer).PageCount %>"></asp:Label>

页°3

<asp:LinkButton ID="LinkButtonFirstPage" runat="server"
CommandArgument="First"
CommandName="Page"

Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0
%>'>首º¡Á页°3</asp:LinkButton>

<asp:LinkButton ID="LinkButtonPreviousPage" runat="server"
CommandArgument="Prev"

CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex !=
0 %>'>上¦?一°?页°3</asp:LinkButton>

<asp:LinkButton ID="LinkButtonNextPage" runat="server"
CommandArgument="Next"
CommandName="Page"

Visible='<%# ((GridView)Container.NamingContainer).PageIndex !=
((GridView)Container.NamingContainer).PageCount - 1 %>'>下?一°?页°3</asp:LinkButton>

<asp:LinkButton ID="LinkButtonLastPage" runat="server"
CommandArgument="Last"
CommandName="Page"

Visible='<%# ((GridView)Container.NamingContainer).PageIndex !=
((GridView)Container.NamingContainer).PageCount - 1 %>'>尾2页°3</asp:LinkButton>

转Áa到Ì?第̨²

<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页°3

<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"

CommandName="Page" Text="GO" />

</PagerTemplate>

protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到该控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex==-3)
        {
            //点击了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) - 1; 
            }
        }
        else
        { 
            //点击了其他的按钮
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        
        //得到新的值
        theGrid.PageIndex = newPageIndex;
        
         //重新绑定
        bingDesignatioonName();
    }

要在GridView中加入//实现分页

AllowPaging="true" PageSize="10"

// 分页时触发的事件
protectedvoid gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gvwDesignationName.PageIndex=e.newIndex;
    bingDesignatioonName();
}

这里我给出一个通用显示分页的模板(网上搜的,自己给出注释)

对应该事件中代码为

<PagerTemplate>

当Ì¡À前¡ã第̨²:

<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1
%>"></asp:Label>

页°3/共2:

<asp:Label ID="LabelPageCount" runat="server" Text="<%#
((GridView)Container.NamingContainer).PageCount %>"></asp:Label>

页°3

<asp:LinkButton ID="LinkButtonFirstPage" runat="server"
CommandArgument="First"
CommandName="Page"

Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0
%>'>首º¡Á页°3</asp:LinkButton>

<asp:LinkButton ID="LinkButtonPreviousPage" runat="server"
CommandArgument="Prev"

CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex !=
0 %>'>上¦?一°?页°3</asp:LinkButton>

<asp:LinkButton ID="LinkButtonNextPage" runat="server"
CommandArgument="Next"
CommandName="Page"

Visible='<%# ((GridView)Container.NamingContainer).PageIndex !=
((GridView)Container.NamingContainer).PageCount - 1 %>'>下?一°?页°3</asp:LinkButton>

<asp:LinkButton ID="LinkButtonLastPage" runat="server"
CommandArgument="Last"
CommandName="Page"

Visible='<%# ((GridView)Container.NamingContainer).PageIndex !=
((GridView)Container.NamingContainer).PageCount - 1 %>'>尾2页°3</asp:LinkButton>

转Áa到Ì?第̨²

<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页°3

<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"

CommandName="Page" Text="GO" />

</PagerTemplate>

protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到该控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex==-3)
        {
            //点击了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) - 1; 
            }
        }
        else
        { 
            //点击了其他的按钮
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        
        //得到新的值
        theGrid.PageIndex = newPageIndex;
        
         //重新绑定
        bingDesignatioonName();
    }

GridView中加入//实现分页的更多相关文章

  1. 在DevExpress程序中使用Winform分页控件直接录入数据并保存

    一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...

  2. ASP.net中GridView中增加一行记录并默认显示为编辑状态

    //添加 protected void Button1_Click(object sender, EventArgs e) { DataSet ds = (DataSet)pa.GetDataSet( ...

  3. GridView中显示时间日期格式问题

    以下都是GridView基本常用的日期,时间格式 形式 语法 结果 注释 数字 {0:N2} 12.36   数字 {0:N0} 13   货币 {0:c2} $12.36   货币 {0:c4} $ ...

  4. 实现CheckBox的三种选中状态(全选、半选、不选)在GridView中模拟树形的功能

    度娘了很多帖子,只说三种状态要用图片替换来做,但没找到有用的例子,被逼自己写了一个 三方控件肯定是很多的,如jstree,可以直接用 由于公司的UDS限制,不能上传图片,只能文字说明了. 就是要在gr ...

  5. Gridview中几个Button的应用

    gridview中有三种方式添加button的应用,CommandField.ButtonField.TemplateField中加Button这三种方式.三种方式都可以实现同样的功能,但在实现某些功 ...

  6. DEV控件中GridView中的复选框与CheckBox实现联动的全选功能

    最初的界面图如图1-1(全选框ID: cb_checkall  DEV控件名称:gcCon ): 要实现的功能如下图(1-2  1-3  1-4)及代码所示: 图1-2 图1-3 图1-4 O(∩_∩ ...

  7. SpringMVC结合easyUI中datagird实现分页

    SpringMVC结合easyUI中datagird实现分页 DataGrid以表格形式展示数据,并提供了丰富的选择.排序.分组和编辑数据的功能支持.轻量级,单元格合并.多列标题.冻结列和页脚只是其中 ...

  8. .net中从GridView中导出数据到excel(详细)

    1,创建数据源 找到要导出的GridView中的数据. 2,重写VerifyRenderingInServerForm方法. public override void VerifyRenderingI ...

  9. GridView中的GridView1_RowCommand事件

    GridView1_RowCommand事件是GridView中生成事件时激发 比如说页面中有一个按钮给他设置CommandName属性 <asp:Button ID="btnCheH ...

随机推荐

  1. Static和static block(静态块)的用法

    一.用法:是一个修饰符,用于修饰成员(成员变量 成员函数)被动态所共享 当成员被静态修饰后,就多了一种调用方式,除了可以被对象调用外,还可以直接被类名调用. 类名.静态成员 二.static特点: 1 ...

  2. [转]CentOS 7忘记root密码解决办法

    转自:http://www.linuxidc.com/Linux/2016-08/134034.htm  亲测可用! CentOS 7 root密码的重置方式和CentOS 6完全不一样,CentOS ...

  3. thinkphp3.2.3代码审计

    <?php namespace Home\Controller; use Think\Controller; class UserController extends Controller { ...

  4. 【vue】父向子组件传参、子组件向父传参

    1.父向子组件传参 App.vue为父,引入componetA组件之后,则可以在App.vue中使用标签(注意驼峰写法要改成componet-a写法,因为html对大小写不敏感,componenta与 ...

  5. Scrum培训小体会

    公司组织Scrum培训. 虽然是针对ScrumMaster这个角色的培训,但更多是基于对Scrum这个敏捷开发实践方法的了解. 回来也有一些感想,记录下来.以后在工作实践中,继续探索.实践.体验.感悟 ...

  6. 1、Spring Cloud - 微服务简介

    前言: 业界大牛马丁.福勒(Martin Fowler) 这样描述微服务: 论文网址:https://martinfowler.com/articles/microservices.html 就目前而 ...

  7. [转载] MySQL 注入攻击与防御

    MySQL 注入攻击与防御 2017-04-21 16:19:3454921次阅读0     作者:rootclay 预估稿费:500RMB 投稿方式:发送邮件至linwei#360.cn,或登陆网页 ...

  8. FreeMarker之根据模板生成Java代码

    FreeMarker根据模板生成Java代码,光这句话,大家想必也知道它的应用了,比如流行的DRY原则,该原则的意思,可简单概述为"不要写重复的代码". 比如Java中三层架构,数 ...

  9. PAT——1071. 小赌怡情

    常言道“小赌怡情”.这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注t个筹码后,计算机给出第二个数.若玩家猜对了,则系统奖励玩家t个筹码:否 ...

  10. 多线程系列之 java多线程的个人理解(二)

    前言:上一篇多线程系列之 java多线程的个人理解(一) 讲到了线程.进程.多线程的基本概念,以及多线程在java中的基本实现方式,本篇主要接着上一篇继续讲述多线程在实际项目中的应用以及遇到的诸多问题 ...