效果如图:

代码如下:

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. nodejs pm2部署配置

    pm2是一个进程管理工具,可以用它来管理你的node进程,并查看node进程的状态,当然也支持性能监控,进程守护,负载均衡等功能. 1.pm2安装使用需要全局安装  npm install -g pm ...

  2. 使用vscode访问和修改远程计算机文件

    使用vscode访问和修改远程文件,分三步实现:在远程linux机器上安装rmate:在本地windows上安装openssh:在vscode中安装扩展remote vscode. 1. 在远程lin ...

  3. 昨天写支付接口时遇到支付接口返回数据接收地址,session数据丢失(或者说失效)的问题

    在网上找了好久 才找到答案 分享给大家 http://www.zcool.com.cn/article/ZMzYwNTI=.html

  4. 5-3 bash脚本编程之二 条件判断

    1. 条件测试的表达式 1. [ expression ]  :注意这个中括号的前后都有一个空格 2. [[ expression ]] 3. test expression 2.条件判断的类型 1. ...

  5. 压缩和解压文件:tar gzip bzip2 compress(转)

    tar[必要参数][选择参数][文件] 压缩:tar -czvf filename.tar.gz targetfile解压:tar -zxvf filename.tar.gz参数说明: -c 建立新的 ...

  6. 项目自动化建构工具gradle 入门0——环境 & 废话

    gradle 是一个项目自动化构建工具.同类的产品还有ant ,maven等等.相比之下我更喜欢gradle,它语法简洁.兼容maven.ide集成很好. 学习使用gradle最快的方式是看文档,而且 ...

  7. 用 JSP 实现对文件的相关操作

    前段时间一直忙着作业,实验,动手的时间真是少之又少,今天终于可以继续和大家分享关于 JSP 的学习心得. 简单总结一下吧: JSP 理论性很强,感觉就是纯语法. 我更偏向于实际编写代码,这样更容易理解 ...

  8. html之select标签

    循环select标签 <select name="group_id"> {% for row in group_list %} <option value={{r ...

  9. dubbox升级spring到4.x及添加log4j2支持

    今天花了点时间,把dubbox依赖的spring从3.x升级成最新版的4.x了,其它一些依赖的组件也顺带升级了,同时dubbo支持的第三方日志组件居然没有log4j2,加了点代码也一并支持了,蛋疼的是 ...

  10. [LeetCode] Min Stack 最小栈

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...