使用方法:

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. CSS3 - chrome,傲游,360极速浏览器不支持小于12px的字号的解决办法

    google流量器chrome,傲游,360极速浏览器都是基于webkit内核浏览器,默认不支持小于font-size小于12px 的字号,即定义font-size小于12px时会发现字体大小依然是1 ...

  2. 【51Nod】1920 空间统计学 状压DP

    [题目]1920 空间统计学 [题意]给定m维空间中的n个点坐标,满足每一维坐标大小都在[0,3]之间,现在对于[0,3*m]的每个数字x统计曼哈顿距离为x的有序点对数.\(n \leq 2*10^5 ...

  3. ASP.NET程序发布

    详细流程请参考文章:https://www.cnblogs.com/wangjiming/p/6286045.html 主要补充个人操作过程中遇到的问题: 1)网站发布完成后,站点下没有aspnet_ ...

  4. Linux内核启动流程分析(一)【转】

    转自:http://blog.chinaunix.net/uid-25909619-id-3380535.html 很久以前分析的,一直在电脑的一个角落,今天发现贴出来和大家分享下.由于是word直接 ...

  5. 数据库SQL语句性能优化

    选择最有效率的表名顺序 ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处理,在FROM子句中包含多个表的情况下 ...

  6. 解决Spring配置文件不显示design和source, namespace 问题

    之前撸代码一直没太关注这个问题,后来发现对于不太熟悉配置文件内容的小伙伴们来说是比较痛苦的,因为每个配置项都需要你记住或者拷贝别人现成配置 那么问题来了,今天在写发现我的Spring配置文件不显示de ...

  7. js和css实现内容超过边框,就自动省略,自动添加title

    在项目汇总,我们有这样的需求,如果内容多了,就自动省略,自动添加title 这个需要判断判断俩个值,一个是width(),一个是scrollWidth, 在div中,如果内容没有超过边框,这俩个值是一 ...

  8. docker 的简单操作

    一直说更博,但是一直在delay.... 最近一直用到docker,所以就总结一下吧! docker的介绍 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. ...

  9. 带你走进Android Afinal框架的世界

    1.什么是Afinal框架? Afinal是一个开源的android的orm和ioc应用开发框架,其特点是小巧灵活,代码入侵量少.在android应用开发中,通过Afinal的ioc框架,诸如ui绑定 ...

  10. .NetCore源码阅读笔记系列之Security (一) Authentication & AddCookie

    如果你使用过.NetCore开发过程序,你会很清楚,在其中我们经常会用到一些如下的代码 services.AddAuthentication(options => { options.Defau ...