一、说明

  AspNetPager.dll这个分页控件主要用于asp.net webform网站,现将整理代码如下

二、代码

  1、首先在测试页面Default.aspx页面添加引用

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

  2、写一个Repeater列表控件用于显示数据

<asp:Repeater ID="rptNews" runat="server">
  <ItemTemplate>
    <li>
      <span><%# Eval("time") %></span>
      <a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a>
    </li>
  </ItemTemplate>
</asp:Repeater>

  3、添加

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px"
FirstPageText="首页" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾页"
meta:resourcekey="AspNetPager1" NextPageText="下一页" PageSize="10" PrevPageText="上一页"
Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb"
OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10">
</webdiyer:AspNetPager>

  PageSize属性是用于设置每页显示的数量

  4、后台代码绑定

//测试数据源
private void ShowNews()
{
  String strSql = String.Format("select * from News order by time asc");
  DataTable dtbl = Access.ExecuteDataTable(strSql, null);
  this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl);
  this.rptNews.DataBind();
}

  Access是测试数据库访问类,在最后的Demo中提供给大家

  5、分页控件点击页码事件

//分页
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
  this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
  ShowNews();
}

  最后奉上整页代码:

  Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asp.net分页控件</title>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.aboutcontentnr{width:100%; height:auto; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul class="news">
<asp:Repeater ID="rptNews" runat="server">
<ItemTemplate>
<li><span>
<%# Eval("time") %></span><a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
<div class="paginator">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px"
FirstPageText="首页" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾页"
meta:resourcekey="AspNetPager1" NextPageText="下一页" PageSize="10" PrevPageText="上一页"
Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb"
OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10">
</webdiyer:AspNetPager>
</div>
</div>
</form>
</body>
</html>

  Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data; public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowNews();
}
} //测试数据源
private void ShowNews()
{
String strSql = String.Format("select * from News order by time asc");
DataTable dtbl = Access.ExecuteDataTable(strSql, null);
this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl);
this.rptNews.DataBind();
} //分页点击页码事件
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
ShowNews();
}
}

三、Demo

  AspNetPager(dll)

  AspNetPage(Demo)

作者:小路 QQ:2490024434 
出处:http://www.cnblogs.com/lengzhan/
本文版权归【冷战】和博客园所有,欢迎转载收藏,未经作者同意须保留此段声明,否则保留追究法律责任的权利。

asp.net分页控件的更多相关文章

  1. 【asp.net爬虫】asp.NET分页控件抓取第n页数据 javascript:__doPostBack

    最近在模拟HTTP请求抓取数据,但是服务器是asp.net开发的 分页控件代码 <tr> <td align="left">共&nbsp210&am ...

  2. asp.net分页控件库

    AspNetPager分页控件 AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的 ...

  3. 小白写的一个ASP.NET分页控件,仅供娱乐

    无聊,第一次写博客,自己动手写了一个分页控件.由于我是新手,有很多地方写得不够好,希望各位大牛多多指正.哈哈哈 /// <summary> /// 分页控件 /// </summar ...

  4. ASP.NET 分页控件

    using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.U ...

  5. 对自写的Asp.Net分页控件的应用方式(异步无刷新分页)

    前台代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" co ...

  6. 我学习的自定义ASP.NET分页控件

    public class MyPagecontroll { public int TotalCount { get; set; }//数据的总条数 public int PageSize { get; ...

  7. asp.net webform 自定义分页控件

    做web开发一直用到分页控件,自己也动手实现了个,使用用户自定义控件. 翻页后数据加载使用委托,将具体实现放在在使用分页控件的页面进行注册. 有图有真相,给个直观的认识: 自定义分页控件前台代码: & ...

  8. asp.net 分页-自己写分页控件

    去年就发表过asp.net 分页-利用后台直接生成html分页 ,那种方法只是单纯的实现了分页,基本不能使用,那时就想写个自己的分页控件,无奈能力有限.最近有点时间了,就自己做出了这个分页控件.我承认 ...

  9. 分页控件-ASP.NET(AspNetPager)

    AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: <div class="oa-el ...

随机推荐

  1. 当web.config文件放置在共享目录下(UNC),启动IIS会提示有错误信息500.19,伴随有错误代码0x80070003和错误代码0x80070005的解决办法

    最近遇到一个很有意思的使用环境,操作人员将所有的网站应用内容投放到共享存储里面,并且使用微软的SMB协议将其以CIFS的方式共享出来,使用Windows Server 2008 R2的IIS将其连接起 ...

  2. .NET CoreCLR开发人员指南(上)

    1.为什么每一个CLR开发人员都需要读这篇文章 和所有的其他的大型代码库相比,CLR代码库有很多而且比较成熟的代码调试工具去检测BUG.对于程序员来说,理解这些规则和习惯写法非常的重要. 这篇文章让所 ...

  3. 缓存、队列(Memcached、redis、RabbitMQ)

    本章内容: Memcached 简介.安装.使用 Python 操作 Memcached 天生支持集群 redis 简介.安装.使用.实例 Python 操作 Redis String.Hash.Li ...

  4. iOS从零开始学习直播之1.播放

      对于直播来说,客户端主要做两件事情,推流和播放.今天先讲播放. 播放流程 1.拉流:服务器已有直播内容,从指定地址进行拉取的过程.其实就是向服务器请求数据. 2.解码:对视屏数据进行解压缩. 3. ...

  5. 基于DDDLite的权限管理OpenAuth.net 1.0版正式发布

    距离上一篇OpenAuth.net的文章已经有5个多月了,在这段时间里项目得到了很多朋友的认可,开源中国上面的Star数接近300,于是坚定了我做下去的信心.最近稍微清闲点,正式推出1.0版,并在阿里 ...

  6. 2000条你应知的WPF小姿势 基础篇<8-14>

    在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师,对C#和WPF有着极深的热情.最为出色的是他维护了两个博客:2,000Things You Should Know ...

  7. ABP(现代ASP.NET样板开发框架)系列之4、ABP模块系统

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之4.ABP模块系统 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)” ...

  8. Python学习--05函数

    Python函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.我们已经知道Python提供了许多内建函数,比如print().但我们 ...

  9. TCP同步与异步,长连接与短连接【转载】

    原文地址:TCP同步与异步,长连接与短连接作者:1984346023 [转载说明:http://zjj1211.blog.51cto.com/1812544/373896   这是今天看到的一篇讲到T ...

  10. Git异常:Cannot delete the branch 'test1' which you are currently on

    GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html ———————————————————————————————————————— ...