使用方法:

1、添加对AspNetPager.dll的引用

2、在页面上拖放控件
3、
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
 
4、控件的基本属性设置
<webdiyer:AspNetPager ID="AspNetPager1"   runat="server" 
           FirstPageText='首页'
        LastPageText='尾页'  PagingButtonSpacing="10px" ShowPageIndexBox="Always" CustomInfoHTML="共%RecordCount%条,第%CurrentPageIndex%页 /共%PageCount% 页"
                                 NextPageText="下一页" PrevPageText ="上一页"
                                 ShowCustomInfoSection="Left"
                                 SubmitButtonText ="Go" TextAfterPageIndexBox ="页" 
            TextBeforePageIndexBox ="转到 " UrlPaging="True" 
            CustomInfoSectionWidth="20%" CustomInfoTextAlign="Center" 
            onpagechanged="AspNetPager1_PageChanged">
        </webdiyer:AspNetPager>
 
5、后台代码
protected void Page_Load(object sender, EventArgs e)
    {
         string sqlStr = "select * from download  where 1=1 ";
        if (key.Text != "")
        {
            sqlStr += "and title like '%" + key.Text + "%' order by id desc";
 
        }
        else
        {
            sqlStr += "order by id desc";
        }
        string s = ConfigurationManager.ConnectionStrings["siteconn"].ConnectionString;            //定义连接字符串
        SqlConnection conn = new SqlConnection(s);  //新建数据库连接对象,其中s是上面的连接字符串
        conn.Open();    //打开与数据库的连接
        SqlCommand cmd = new SqlCommand(sqlStr, conn);
        AspNetPager1.AlwaysShow = true;
        AspNetPager1.PageSize = 15;
        AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
        conn.Close();
        bind();
       
       }
    private void bind()
    {
        string sqlStr = "select * from download  where 1=1 ";
        if (key.Text != "")
        {
            sqlStr += "and title like '%" + key.Text + "%' order by id desc";
 
        }
        else
        {
            sqlStr += "order by id desc";
        }
        string s = ConfigurationManager.ConnectionStrings["siteconn"].ConnectionString;            //定义连接字符串
        SqlConnection conn = new SqlConnection(s);  //新建数据库连接对象,其中s是上面的连接字符串
        conn.Open();    //打开与数据库的连接
        DataSet myds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, conn);
        adapter.Fill(myds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "myds");
        GridView1.DataSource = myds.Tables["myds"];
        GridView1.DataBind(); 
    }
   
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bind();
    }
 
6、添加序号
 <asp:TemplateField HeaderText="序号"> 
<ItemTemplate> 
<%# (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize + Container.DataItemIndex + 1%> 
</ItemTemplate> 
</asp:TemplateField>
 

精美样式:

分页是Web应用程序中最常用到的功能之一,AspNetPager  简单实用,应用到项目后台中,棒极了!

自定义样式:

<style type="text/css">
/*拍拍网风格*/
.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;} /*淘宝风格*/
.paginator { font: 12px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {border:solid 1px #ccc;color:#0063dc;cursor:pointer;text-decoration:none;}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {border:1px solid #F50;font-weight:700;color:#F50;background-color:#ffeee5;}
.paginator a:hover {border:solid 1px #F50;color:#f60;text-decoration:none;}
.paginator a,.paginator a:visited,.paginator .cpb,.paginator a:hover
{float:left;height:16px;line-height:16px;min-width:10px;_width:10px;margin-right:5px;text-align:center;
white-space:nowrap;font-size:12px;font-family:Arial,SimSun;padding:0 3px;}
</style>
前台:
<table cellpadding="0" cellspacing="0" align="center" width="99%" class="border">
<tr>
<td align="left" colspan="2">
<webdiyer:AspNetPager ID="AspNetPager1" CssClass="paginator" CurrentPageButtonClass="cpb" runat="server" AlwaysShow="True"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PageSize="20" PrevPageText="上一页" ShowCustomInfoSection="Left"
ShowInputBox="Never" onpagechanged="AspNetPager1_PageChanged" CustomInfoTextAlign="Left" LayoutType="Table" >
</webdiyer:AspNetPager>
</td>
</tr>
</table>

后台:

void bindData()
{
.......绑定语句
this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount, this.AspNetPager1.PageSize });
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
bindData();
}

效果三如下:

做的不是很好看,希望大家不要丢砖头,俺的头没包棉絮,伤不起 ~—_—~

CSS样式表:

/* AspNetPager Style Power By http://www.edweb.cn */
.pager{ width:95%;  margin:10px; line-height:20px; display:block;}
.pager span { border:1px solid #CCCCCC; margin: 0 5px; padding: 1px 6px; float:left;}
.pager a {
    border: 1px solid #CCCCCC;
    display: block;
    overflow:hidden;
    float: left;
    margin: 0 5px;
    padding: 1px 6px;   
}
.pager a:hover { border:1 solid red; background-color:#993399; color:#ffffff; margin: 0 5px; padding: 1px 6px;}

调用方式:在分页控件的外面加一个div包裹起来,直接调用

<div class="pager">
                <webdiyer:AspNetPager ID="Pager" runat="server" FirstPageText="首页" LastPageText="尾页" NextPageText="后页" OnPageChanging="Pager_PageChanging" PageSize="9" PrevPageText="前页" NumericButtonCount="9">
                </webdiyer:AspNetPager>
            </div>

AspNetPager 控件使用的更多相关文章

  1. AspNetPager控件分页使用方法

    AspNetPager控件官方下载地址:http://www.webdiyer.com/aspnetpager/ 把控件加到项目中(添加自定义控件的方法),并把它拖放到页面上 <asp:Scri ...

  2. AspNetPager控件报错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$Aspnetpager1_input问题解决[摘]

    高版本IE,如IE10或者IE11在浏览页面时出现错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$ ...

  3. Entity Framework后台采用分页方式取数据与AspNetPager控件的使用

    本文是一个对AspNetPager控件使用的笔记! 有关AspNetPager控件可以查看杨涛主页.这是一个开放的自定义ASP.NET控件,支持各种自定义的数据分页方式,使用很方便,而且功能也很强大, ...

  4. 使AspNetPager控件中文显示分页信息

    在日常的编程过程中,很多学员对于使AspNetPager控件中文显示分页信息不是很清楚,本文将由达内的老师为各位学员介绍一下使AspNetPager控件中文显示分页信息的内容. AspNetPager ...

  5. (转) .NET实现Repeater控件+AspNetPager控件分页

    SqlConnection (.NET C#) 连接及分页 .net的访问数据机制决定了访问大量数据时会致使客户端机器消耗大量资源,因此有必要对数据进行分页显示,开发工具vs.net+sqlserve ...

  6. AspNetPager控件的最基本用法

    AspNetPager控件是一个基于.net的第三方免费开源控件,具有开发高效.使用方便.功能完整等优点.它弥补了GridView内置分页以及PageDatasource类辅助分页的不足,将分页数据逻 ...

  7. MVC中,加入的一个aspx页面用到AspNetPager控件处理办法

    今天项目遇到了如题所示的问题,按照官方的案例介绍做分页,简直要奔溃了, 使用URL重写,但是page总是1,根本不跳, 不使用URL重写,又出现,第一页是 http://aa.com/view_asp ...

  8. AspNetPager控件的简单使用

    1.首先引用这个控件. 在前台页面上修改一些属性. <webdiyer:AspNetPager ID=" AlwaysShow="true" FirstPageTe ...

  9. 使用AspNetPager控件分页

    页面后台写法 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } pro ...

随机推荐

  1. 解决Winsock2.h和afxsock.h定义冲突的办法

    如果我们在工程中使用了afxsock.h,但在其它的地方又加了些 使用winsock2.h,哈哈,VC会告诉你一大堆错误,大意就是有定义重复,该怎么解决? 由于MFC的SOCKET类使用的是Winso ...

  2. HDU 2112 HDU Today 最短路

    题目描述: Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这 ...

  3. Spark笔记之使用UDF(User Define Function)

    一.UDF介绍 UDF(User Define Function),即用户自定义函数,Spark的官方文档中没有对UDF做过多介绍,猜想可能是认为比较简单吧. 几乎所有sql数据库的实现都为用户提供了 ...

  4. PWN入门

    pwn ”Pwn”是一个黑客语法的俚语词 ,是指攻破设备或者系统 .发音类似“砰”,对黑客而言,这就是成功实施黑客攻击的声音——砰的一声,被“黑”的电脑或手机就被你操纵.以上是从百度百科上面抄的简介, ...

  5. 【C++】wchar、char格式化符输出

    VC.BCB.MinGW Linux下的GCC.C99标准 printf wprintf printf wprintf s char wchar_t char S wchar_t char * hs ...

  6. python之celery使用详解(二)

    前言 前面我们了解了celery的基本使用后,现在对其常用的对象和方法进行分析. Celery对象 核心的对象就是Celery了,初始化方法: class Celery(object): def __ ...

  7. git stash命令使用手册

    修改记录压栈保存: git stash push -u -m "msg" // -u ~ --意思是包含未被跟踪的文件git stash push -m "msg&quo ...

  8. 最小二乘法 及python 实现

    参考   最小二乘法小结     机器学习:Python 中如何使用最小二乘法 什么是” 最小二乘法” 呢 定义:最小二乘法(又称最小平方法)是一种数学优化技术,它通过最小化误差的平方和寻找数据的最佳 ...

  9. weex官方demo weex-hackernews代码解读(上)

    一.介绍 weex 是阿里出品的一个类似RN的框架,可以使用前端技术来开发移动应用,实现一份代码支持H5,IOS和Android.最新版本的weex已默认将vue.js作为前端框架,而weex-hac ...

  10. 兼容到ie10的js文件导出、下载到本地

    话不多说,上代码: try { let reader = new FileReader(); let blob = new Blob([res.data], { type: 'application/ ...