标签:des style blog http color 使用 os io
1.【添加AspNetPager.dll文件】
2.【使用方法】
public static DataTable GetRecord(SystemModel.Pager mt, ref int TotalPage, ref int TotalRecord) { string sortType = mt.SortType == 1 ? " asc" : " desc"; //查询总条数 string _strCountSQL = "select count(" + mt.PrimaryKey + ") from " + mt.TableName + " where " + mt.Where; string _strPageSQl = "select top " + mt.PageSize + " " + mt.FiledList + " from " + mt.TableName + " where " + mt.PrimaryKey + " not in(select top " + mt.PageSize * (mt.PageIndex - 1) + " " + mt.PrimaryKey + " from " + mt.TableName + " where " + mt.Where + " order by " + mt.Order + sortType + "," + mt.PrimaryKey + " " + sortType + ") and " + mt.Where + " order by " + mt.Order + sortType + "," + mt.PrimaryKey + " " + sortType; if (mt.PageIndex == 1) { _strPageSQl = "select top " + mt.PageIndex * mt.PageSize + " " + mt.FiledList + " from " + mt.TableName + " where " + mt.Where + " order by " + mt.Order + sortType + "," + mt.PrimaryKey + " " + sortType; } DataSet ds = DBUtility.AccessHelper.Query(_strPageSQl); TotalRecord = int.Parse(DBUtility.AccessHelper.GetSingle(_strCountSQL).ToString()); TotalPage = TotalRecord % mt.PageSize == 0 ? TotalRecord / mt.PageSize : TotalRecord / mt.PageSize + 1; return ds.Tables[0]; }
也可以使用存储过程分页,这里的参数要返回一共多少页,当前第几页。
create procedure home (@pagesize int, @pageindex int, @docount bit) as if(@docount=1) select count(*) from binfo else begin with temptbl as ( SELECT ROW_NUMBER() OVER (ORDER BY time desc)AS Row, * from binfo O ) SELECT * FROM temptbl where Row between (@pageindex-1)*@pagesize+1 and (@pageindex-1)*@pagesize+@pagesize end
3.【页面中使用】
index.asx页面:
<webdiyer:AspNetPager ID="Pager22" runat="server" AlwaysShow="true" Font-Size="12px" CurrentPageButtonClass="cpb" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" CustomInfoTextAlign="Right" ShowPageIndexBox="Never" ShowCustomInfoSection="Left" CenterCurrentPageButton="True" ShowFirstLast="true" ReverseUrlPageIndex="True" Direction="LeftToRight" Width="100%" OnPageChanging="Pager_PageChanging" ForeColor="Black" NumericButtonCount="100"> </webdiyer:AspNetPager>
具体参数,可以查下相关的属性。
index.aspx.cs
SystemModel.Pager mt = new SystemModel.Pager(); mt.PageIndex = PageIndex; mt.PageSize =分页数量; mt.TableName =表名; mt.FiledList = 查询的内容,如*; mt.PrimaryKey = 主键; mt.Where =条件; if (HttpContext.Current.Request["id"] != null) { mt.Where = mt.Where + " and fid=" + int.Parse(HttpContext.Current.Request["id"].ToString()); } mt.Order = 排序字段; mt.SortType = 排序方式(1或2); mt.RecorderCount = 0; int TotalPage = 1; int TotalRecord = 0; dtNews = SystemBLL.Pager.GetRecord(mt, ref TotalPage, ref TotalRecord); if (dtNews.Rows.Count < 1) { return; } DataView dv = dtNews.DefaultView; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dv; pds.AllowPaging = true; pds.CurrentPageIndex = Pager22.CurrentPageIndex - 1; pds.PageSize = Pager22.PageSize; this.Pager22.PageSize = mt.PageSize; this.Pager22.RecordCount = TotalRecord; this.Pager22.CustomInfoHTML = string.Format("共 {0} 页,当前第 {1} 页,共 {2} 条记录", TotalPage, PageIndex, TotalRecord); if (TotalRecord <= mt.PageSize) { this.Pager22.Style.Add("display", "none"); } else { this.Pager22.Style.Add("display", "block"); }
这里只有常用的一些属性,还有自定义url css之类的
也支持mvc
更多属性请查看这里:http://www.webdiyer.com/aspnetpager/
效果:
AspNetPager 分页的详细用法(ASP.NET),布布扣,bubuko.com
标签:des style blog http color 使用 os io
原文地址:http://www.cnblogs.com/vanteking/p/3927696.html