使用方法:

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. PHP使用数据库的并发问题

    在并行系统中并发问题永远不可忽视.尽管PHP语言原生没有提供多线程机制,那并不意味着所有的操作都是线程安全的.尤其是在操作诸如订单.支付等业务系统中,更需要注意操作数据库的并发问题. 接下来我通过一个 ...

  2. Linux - awk 文本处理工具四

    awk 常用示例 获取本机 IP 方式 /sbin/ifconfig |awk -v RS="Bcast:" '{print $NF}'|awk -F: '/addr/{print ...

  3. MFC笔记(DN)

    01:MFC应用程序编程 02:MFC菜单.工具栏.状态栏 03:视图窗口

  4. 第8月第15天 app支持后台播放

    1. AVAudioSession *audioSession = [AVAudioSession sharedInstance]; //默认情况下扬声器播放 [audioSession setCat ...

  5. mysql.user细节三问

    一.如何拒绝用户从某个精确ip访问数据库假如在mysql.user表中存在用户'mydba'@'192.168.85.%',现在想拒绝此用户从某个精确ip访问数据库 # 创建精确ip用户,分配不同的密 ...

  6. Linux sleep命令

    Linux sleep命令可以用来将目前动作延迟一段时间. 使用权限:所有使用者. 语法 sleep [--help] [--version] number[smhd] 参数说明: --help : ...

  7. imperva—waf 敏感字段显现

    imperva WAF中看到的日志内容信息有些都是敏感的  比如登录登出的信息 如何调整敏感信息的现实方式,并可以自定义敏感字段? 这里添加字段就可以了 这样就将******转变为明文了

  8. Linux驱动技术(四) _异步通知技术【转】

    转自:https://www.cnblogs.com/xiaojiang1025/p/6376561.html 异步通知的全称是"信号驱动的异步IO",通过"信号&quo ...

  9. linux系统下如何批量更改文件夹里面所有相同字符【转】

    如网上源码下载下来我们需要调试,调试过程中需要修改里面相同文字,下面提供三种方法供参考 通过sed命令替换 sed -i "s/oldyunwei/newyunwei/g" gre ...

  10. java多线程计算和

    如题:如何利用多线程实现1~1000000000的和 本文利用Callable可以返回值的特性,并将执行结果用CompletionService进行存储,最后将分步值累加. import java.u ...