效果如图:

代码如下:

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. v$session中server为none与shared值解析

    查询V$SESSION,你会看到SERVER可能会有DEDICATED| SHARED| PSEUDO| NONE 四种值,如果SERVER字段的值除了DEDICATED,还有NONE,则说明当前实例 ...

  2. 自制xml实现SQL动态参数配置

    此文章是基于 搭建SpringMVC+Spring+Hibernate平台 一. 准备工作 1. 点击此找到并下载 commons-digester3-3.2.jar 2. 点击此找到并下载 comm ...

  3. python-pickle模块使用实例

    以下代码主要实现的是用户登录,注册,密码验证,账户锁定,重置和修改密码等功能 import pickle #第一次运行请去掉下面一段代码的注释 ''' users_db = open("us ...

  4. WPF 自定义标题栏 自定义菜单栏

    自定义标题栏 自定义列表,可以直接修改WPF中的ListBox模板,也用这样类似的效果.但是ListBox是不能设置默认选中状态的. 而我们需要一些复杂的UI效果,还是直接自定义控件来的快 GitHu ...

  5. jquery的bind跟on绑定事件的区别

    jquery的bind跟on绑定事件的区别:主要是事件冒泡: jquery文档中bind和on函数绑定事件的用法: .bind(events [,eventData], handler) .on(ev ...

  6. [LeetCode] Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  7. [LeetCode] Single Number II 单独的数字之二

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  8. openssl用法详解

    OpenSSL 是一个开源项目,其组成主要包括一下三个组件: openssl:多用途的命令行工具 libcrypto:加密算法库 libssl:加密模块应用库,实现了ssl及tls openssl可以 ...

  9. javascript-style-guide

    /* 1.类型types 原始值:存取直接作用于它自身 string number boolean null undefined var foo=1; var bar=foo; bar=9; cons ...

  10. electron 入门小白贴

    electron 入门小白贴 electron demo 跑起来! 毕设准备是做个 跨平台的做题的客户端,打算用 electron 来弄. 然而今天折腾了半天才终于吧demo给跑起来了.经历了许多的问 ...