using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Pagination : WebBlockUserControl { public int MaxResults { get { return (ViewState["MaxResults"] == null ? -1 : (int)ViewState["MaxResults"]); } set { ViewState["MaxResults"] = value; } } private int _PageSize = -1; public int PageSize { get { if (_PageSize == -1) { string ps = Configuration.Get("BrowsePageSize"); if (ps == null || ps.Length == 0) _PageSize = 15; else _PageSize = Int32.Parse(ps); } return _PageSize; } } private int _PageIndex = 1; public int PageIndex { get { if (Request["Page"] != null) { if (!Int32.TryParse(Request["Page"], out _PageIndex)) throw new Exception("Please specify an integer page index."); } else _PageIndex = 1; return _PageIndex; } } private int _LowRow = 0; public int LowRow { get { if (_LowRow == 0) _LowRow = ((PageIndex-1) * PageSize) +1; return _LowRow; } } private int _HighRow = 0; public int HighRow { get { if (_HighRow == 0) _HighRow = (PageIndex * PageSize) + 1; return _HighRow; } } protected override void Render(HtmlTextWriter writer) { int TotalPages = Math.Max(1, (int)Math.Ceiling((double)MaxResults / PageSize)); if(PageIndex == -1) { TotalPages = 1; } if (TotalPages > 1) // build out paging { writer.Write("