要在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. 021.10 IO流 打印流

    内容:PrintStream:字节流    PrintWriter:字符流 PrintStream public static void main(String[] args) throws IOEx ...

  2. ZooKeeper学习之路 (六)ZooKeeper API的简单使用(二)级联删除与创建

    编程思维训练 1.级联查看某节点下所有节点及节点值 2.删除一个节点,不管有有没有任何子节点 3.级联创建任意节点 4.清空子节点 ZKTest.java public class ZKTest { ...

  3. Odoo中如何复制有唯一性约束的记录?

    转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9281393.html  如果为模型的字段添加了唯一性约束,那么在记录的form视图功能菜单上选择“复制”时就会 ...

  4. WEB安全 魔术引号及注入类型

    一.魔术引号 1. magic_quotes_gpc 变量 什么是魔术引号 Warning本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除.当打开时,所有的 '(单引号),&q ...

  5. QTP基本方法

    1.for循环: m代表间隔循环长度: 如果m>0,则j要大于i: 如果m<0,则i要大于j: for i to j [step m] 语句块 [exit for]//强制退出循环 nex ...

  6. yum 安装 php5.6

    yum 安装 php5.6 安装 PHP rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/i386/epel-release-6-8.noa ...

  7. Mybatis Plus简介

    集成 MP Mybatis-Plus 的集成非常简单,对于 Spring,我们仅仅需要把 Mybatis 自带的MybatisSqlSessionFactoryBean替换为 MP 自带的即可. &l ...

  8. EF Core 中DbContext不会跟踪聚合方法和Join方法返回的结果,及FromSql方法使用讲解

    EF Core中: 如果调用Queryable.Count等聚合方法,不会导致DbContext跟踪(track)任何实体. 此外调用Queryable.Join方法返回的匿名类型也不会被DbCont ...

  9. C/S模式,发布/订阅模式和PUSH/PULL模式(上)

    CS模式(客户端/服务器模式) 最场景的信息传递模式,也称为Request/Response模式,或者调用模式.http/https协议即此模式.因为最常用所以大家一般都比较熟悉,这里不重点讲了,大家 ...

  10. 【腾讯敏捷转型No.7】QQ邮箱如何通过敏捷成为行业第一

    前几篇文章讲到2006年的腾讯是如何开始敏捷转型的,接下来这篇文章,我将向大家讲述,腾讯开始敏捷转型之后,QQ邮箱是如何通过敏捷成为行业第一. 众所周知,张小龙是“微信之父”,对他熟悉的人,应该也知道 ...