AspNetPager控件使用方法初探

孤街浪徒 提交于 2020-03-17 01:27:49

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

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>

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!