效果如图:

代码如下:

aspx页:

<asp:GridView ID="GridViewMain" runat="server"

OnPageIndexChanging="GridViewMain_PageIndexChanging"

ondatabound="GridViewMain_DataBound"

PageSize="10">

<PagerTemplate>
         <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)  + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label> 
         <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页"  Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton> 
        <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev"  ></asp:LinkButton> 
        <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton> 
         <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页"   Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton> 
         到第<asp:dropdownlist id="PageDropDownList"
                  autopostback="true"
                  onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
                  runat="server"/> 页 
         
     </PagerTemplate>

cs页

protected void GridViewMain_PageIndexChanging(object sender,GridViewPageEventArgs e)

{

GridViewMain.PageIndex = e.NewPageIndex;

InitListFillData();   //数据绑定

}

protected void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)

{

// Retrieve the pager row.

GridViewRow pagerRow = GridViewMain.BottomPagerRow;

// Retrieve the PageDropDownList DropDownList from the bottom pager row.

DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");

// Set the PageIndex property to display that page selected by the user.

GridViewMain.PageIndex = pageList.SelectedIndex;

InitListFillData();   //数据绑定

}

protected void GridViewMain_DataBound(Object sender, EventArgs e)

{

GridViewMain.BottomPagerRow.Visible = true;//只有一页数据的时候也再下面显示pagerrow,需要top的再加Top

// Retrieve the pager row.

GridViewRow pagerRow = GridViewMain.BottomPagerRow;

// Retrieve the DropDownList and Label controls from the row.

DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");

Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");

if (pageList != null)

{

// Create the values for the DropDownList control based on

// the  total number of pages required to display the data

// source.

for (int i = 0; i < GridViewMain.PageCount; i++)

{

// Create a ListItem object to represent a page.

int pageNumber = i + 1;

ListItem item = new ListItem(pageNumber.ToString());

// If the ListItem object matches the currently selected

// page, flag the ListItem object as being selected. Because

// the DropDownList control is recreated each time the pager

// row gets created, this will persist the selected item in

// the DropDownList control.

if (i == GridViewMain.PageIndex)

{

item.Selected = true;

}

// Add the ListItem object to the Items collection of the

// DropDownList.

pageList.Items.Add(item);

}

}

if (pageLabel != null)

{

// Calculate the current page number.

int currentPage = GridViewMain.PageIndex + 1;

// Update the Label control with the current page information.

pageLabel.Text = "Page " + currentPage.ToString() +

" of " + GridViewMain.PageCount.ToString();

}

}

GridView利用PagerTemplate做分页显示设置上一页下一页转到下拉转页的更多相关文章

  1. 利用jquery+iframe做一个ajax上传效果

    以下是自学it网--中级班上课笔记 网址:www.zixue.it html页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict ...

  2. GridView中加入//实现分页

    要在GridView中加入//实现分页 AllowPaging="true" PageSize="10" // 分页时触发的事件 protectedvoid g ...

  3. 用PHP+MySQL来做分页的演示

    用php做分页弄懂逻辑关系其实不难,不过我在听课的时候估计是被老师讲的那些变量里的英文单词给听懵了,因为有几个变量的名字都很像,只是换了两三个英文字母而已,有的就少几个这样的,听到一半已经不知道老师讲 ...

  4. Ajax做分页

    Ajax做分页 用这种ajax做分页的方法比较简单,把代码直接复制就可以,然后根据实际更改一下里面的参数. .设置分页显示显示的样式,显示效果如下. 复制代码 <style type=" ...

  5. 利用多线程资源竞争技术上传shell

    通过多线程资源竞争的手段同时上传两个头像,就可以在Apache+Rails环境下实现远程代码执行.这并不是天方夜谭,同时我相信许多文件上传系统都会有这个漏洞……这是一个非常有趣的安全实验,一起来看看吧 ...

  6. 如何利用express新建项目(上)

    如何利用express新建项目(上) 摘要 这篇文章将讲解了如何快速利用express新建项目 一.express4.x的安装 1. npm install -g express 2. npm ins ...

  7. [ASP.NET] 如何利用Javascript分割檔案上傳至後端合併

    最近研究了一下如何利用javascript進行檔案分割上傳並且透過後端.特地記錄一下相關的用法 先寫限制跟本篇的一些陷阱 1.就是瀏覽器的支援了 因為本篇有用到blob跟webworker 在ie中需 ...

  8. 利用Python做绝地科学家(外挂篇)

    i春秋作家:奶权 前言  玩吃鸡时间长的鸡友们 应该都知道现在的游戏环境非常差 特别在高端局 神仙满天飞 搞得很多普通玩家非常没有游戏体验  因为吃鸡的火爆 衍生出了一条巨大的外挂利益链 导致市面上出 ...

  9. ASP利用xhEditor编辑器实现图片上传的功能。

    本人这几天在做一个软件,无意中用到xhEditor在线编辑器,这个编辑器虽然看着比较简单,但功能非常强大,大家可以去官网上查看,废话不说了. 这篇文件主要是实现在ASP环境中利用xhEditor编辑器 ...

随机推荐

  1. 分布式一致性算法--Raft

    前面一篇文章讲了Paxos协议,这篇文章讲它的姊妹篇Raft协议,相对于Paxos协议,Raft协议更为简单,也更容易工程实现.有关Raft协议和工程实现可以参考这个链接https://raft.gi ...

  2. linux基础知识3_根文件系统详解

    文件系统: rootfs:根文件系统 /boot:系统启动相关的文件,如内核.initrd以及grub /dev:设备文件 块设备:随机访问 字符设备:线性访问,按字符为单位 设备号:主设备号(maj ...

  3. css3 text-overflow和white-space,word-wrap,word-break进阶

    一.text-overflow 1.text-overflow作用 简单来说,text-overflow用来设置文本溢出时是否用省略标记(...) 准确的说是设置溢出的文本在不显示的情况下怎样展示给用 ...

  4. Ubuntu15.10下华南师大锐捷认证客户端的使用详解

    本文测试Linux系统环境为Ubuntu15.10 Destop,暂未在其他系统下验证过,不代表LTS版本或较旧的版本按照本文所述方法可以100%正确使用最新的锐捷认证客户端. 本文面向对象为华南师范 ...

  5. easy_UI 投票列表

    首先我们考虑一下在项目投票种用到的属性(ID,投票标题,备选项目,参与人数) entity package cn.entity; public class GridNode { private Lon ...

  6. jpa+springmvc+springdata(一)

    学习尚硅谷笔记: 首先配置application.xml: <?xml version="1.0" encoding="UTF-8"?> <b ...

  7. linux 项目部署问题

    1.ubuntu 安装 pillow 报错 缺少依赖包 pip install Pillow ValueError: zlib is required unless explicitly disabl ...

  8. C语言学习 第十一次作业总结

    作业总结 两次的作业,都是和指针有关.从第一次的作业开始,我就多次让同学们思考这个问题:为什么要用指针,为什么在函数的形参中要使用指针.如果能够想明白这2个问题,那么同学们应该会指针的了解就差不多足够 ...

  9. EntityFramework之监听者判断SQL性能指标

    前言 当我们利用EF这个ORM框架时,我们可能会利用LINQ或者原生的SQL语句来进行数据操作,此时我们无法确定我们的代码是否会给数据库带来一定的负载,当给数据库带来一定的压力时,由于项目中对数据进行 ...

  10. iOS中富文本NSMutableAttributedString的用法

    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:@"我是富文 ...