AspNetPager控件使用方法初探


只是我一直忽视的一个控件,最近才发现它很好用。用法也非常简单。

1.将dll文件添加进项目,在页面中引用

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

2.将其放入需要的位置,其中有相关参数的设置

 <webdiyer:aspnetpager ID="AspNetPager1" runat="server" AlwaysShow="True"
                  FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PrevPageText="上一页"
                  onpagechanged="AspNetPager1_PageChanged" NumericButtonCount="4"  PageSize="5">
              </webdiyer:aspnetpager>

3.绑定数据

            PagedDataSource pd = new PagedDataSource();
            pd.DataSource = NewsManager.listNewShow(Ipid);

            pd.AllowPaging = true;
            if (pd.DataSourceCount > AspNetPager1.PageSize)
            {
                this.AspNetPager1.AlwaysShow = true;
            }
            this.AspNetPager1.RecordCount = pd.DataSourceCount;
            pd.PageSize = this.AspNetPager1.PageSize;
            pd.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            DataList1.DataSource = pd;
            DataList1.DataBind();

4.页面生成的代码,配合设计编写相关CSS样式

<div id="AspNetPager1">

 <a disabled="true" style="margin-right:5px;">首页</a><a disabled="true" style="margin-right:5px;">上一页</a><span style="margin-right:5px;font-weight:Bold;color:red;">1</span><a href="javascript:__doPostBack('AspNetPager1','2')" style="margin-right:5px;">2</a><a href="javascript:__doPostBack('AspNetPager1','2')" style="margin-right:5px;">下一页</a><a href="javascript:__doPostBack('AspNetPager1','2')" style="margin-right:5px;">末页</a>

</div>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM