效果如图:

代码如下:

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. Percona TokuDB

    Percona TokuDB Percona TokuDB 1.     TokuDB说明 2.     TokuDB安装 3.     使用TokuDB 3.1 快速插入和富索引 3.2 聚集sec ...

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

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

  3. android 获取IMSI信息(判断是移动,联通,电信手机卡)

    首先我们需要知道手机IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信.那么第一步就是先获取手机IMSI号码:代码如下 /** *获取IMSI信息 * ...

  4. php在5.5.0默认提供了Zend OPcache

    eaccelerator无法兼容php5.5.0,好在php在5.5.0默认提供了Zend OPcache,所以一直习惯eaccelerator的朋友如果要升级到php5.5.0的话,可能要暂时和ea ...

  5. HideFlag隐藏标识

    前言 如何让一个Gameobject的属性在运行时,不可以在属性面板上手动的修改呢? 文档:http://www.ceeger.com/Script/Enumerations/HideFlags/Hi ...

  6. Hemodynamic response function (HRF) - FAQ

    Source: MIT - Mindhive What is the 'canonical' HRF? The very simplest design matrix for a given expe ...

  7. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  8. Jquery揭秘系列:实现$.fn.extend 和$.extend函数

    前面我们扩展了bind方法和ready函数,这次我要讲一下$.fn.extend 和$.extend函数. 其他的不多说,直接切入主题吧! 先来看看这两个函数的区别: $.fn.extend是为查询的 ...

  9. 供销大集-JS修改

    aes("a123456") 1.搜索password 可以猜测 寻找匹配项 然后把密码 给t 2.也可以直接直接从这里往上,找到一个 encrypt函数下断点调试输出 funct ...

  10. 【数据库】_由2000W多条开房数据引发的思考、实践----给在校生的一个真实【练耙场】,同学们,来开始一次伟大的尝试吧。

      ×   缘起---闲逛博客园 前几天的时候,在某一QQ群看到一条消息“XXX酒店开房XXXBTXX迅雷BT下载”,当时是一目十行的心态浏览,目光掠过时, 第一反应我想多了~以为是XX种子(你懂的~ ...