C#自己写的一个自定义分页控件
分页以前一直是用第三方分页控件AspNetPager.dll,使用起来也挺方便的,就是样式设置起来感觉不是很好,于是经理决定我们自己做一个分页控件,这个任务就交到我的手上。这个自定义分页控件是模仿58同城的分页及结合我们现在项目的需要写的。感觉比较实用,没什么亮点。
其实分页控件也没啥,就是生成相关的HTML代码,你需要啥HTML代码,用你的代码生成就是了,不管是AspNetPager.dll还是58同城也都是生成分页相关的HTML代码,其实就是一堆a标签,点分页的时候,分页控件所在的页面会刷新。
一:用AspNetPager.dll实现的分页
图:
生成的源码
<div id="ctl00_Content_AspNetPager1"><a disabled="disabled" style="margin-right:5px;">首页</a><a disabled="disabled" style="margin-right:5px;">上一页</a><span class="al" style="margin-right:5px;">1</span><a href="NewsList.aspx?page=2" style="margin-right:5px;">2</a><a href="NewsList.aspx?page=3" style="margin-right:5px;">3</a><a href="NewsList.aspx?page=4" style="margin-right:5px;">4</a><a href="NewsList.aspx?page=5" style="margin-right:5px;">5</a><a href="NewsList.aspx?page=6" style="margin-right:5px;">6</a><a href="NewsList.aspx?page=7" style="margin-right:5px;">7</a><a href="NewsList.aspx?page=2" style="margin-right:5px;">下一页</a><a href="NewsList.aspx?page=7" style="margin-right:5px;">尾页</a></div> 二:58同城的分页
图:
生成的源码
<div class="pager"> <strong><span>1</span></strong><a href="/zufang/pn2/"><span>2</span></a><a href="/zufang/pn3/"><span>3</span></a><a href="/zufang/pn4/"><span>4</span></a><a href="/zufang/pn5/"><span>5</span></a><a href="/zufang/pn6/"><span>6</span></a><a href="/zufang/pn7/"><span>7</span></a><a href="/zufang/pn8/"><span>8</span></a><a href="/zufang/pn9/"><span>9</span></a><a href="/zufang/pn10/"><span>10</span></a><a href="/zufang/pn11/"><span>11</span></a><a href="/zufang/pn12/"><span>12</span></a><a class="next" href="/zufang/pn2/"><span>下一页</span></a></div>
三:我的分页控件
程序代码
<os:PagingControl runat="server" ID="paginglist" PageSize="4" CssCurrent="curpage" ImgFirst="/images/index/btn_first.jpg" ImgPrev="/images/index/btn_prev.jpg" ImgNext="/images/index/btn_next.jpg" ImgLast="/images/index/btn_end.jpg" CssClass="pagelist"></os:PagingControl>paginglist.RecordCount = 200;
paginglist.LoadControl();
生成源码
<div class='pagelist'><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=1'><img src=/images/index/btn_first.jpg/></a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=23'><img src=/images/index/btn_prev.jpg/></a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=14'>14</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=15'>15</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=16'>16</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=17'>17</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=18'>18</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=19'>19</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=20'>20</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=21'>21</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=22'>22</a><a href='/CommonQuestion/QuestionListContent.aspx?questionTypeID=0&page=23'>23</a><span class=curpage>24</span></div>
程序源码
using System.Text;using System.Web;using System.Web.UI;using System.ComponentModel;using System.Collections.Generic;using System.Web.UI.WebControls;//自定义分页控件namespace ObjectCommon.Libary.Component{ [ToolboxData("<{0}:PagingControl runat=\"server\"></{0}:PagingControl>"), DefaultProperty("")] public class PagingControl : Literal { #region 分页属性 private int pageSize = 10; public int PageSize { set { if (value > 0) { pageSize = value; } } get { return pageSize; } } private int pageIndex = 1; public int PageIndex { set { if (value > 0) { pageIndex = value; } } get { return pageIndex; } } public int RecordCount { set; get; } private int PageCount = 0; &n
补充:软件开发 , C# ,