//create the pagination as LinkButtons private void CreateLinkButtonPagination() { pnlPager.Controls.Clear(); //finidng the central postion of display entries. The current page will be shown in the center int ne_half = int.Parse(Math.Ceiling(decimal.Parse(DisplayEntriesCount.ToString()) / 2).ToString()); //retrieving the number of pages int np = TotalPages(); int upper_limit = np - DisplayEntriesCount; //finding the start position of the main pager strip int start = _CurrentPageIndex > ne_half?Math.Max(Math.Min(_CurrentPageIndex - ne_half, upper_limit), 0) : 0; //finding the end position of the main pager strip int end = _CurrentPageIndex > ne_half?Math.Min(_CurrentPageIndex + ne_half, np) : Math.Min(DisplayEntriesCount, np); // Begin by creating the 'Previous' Link if (PreviousPageText.Length > 0) { CreateButton(_CurrentPageIndex - 1, PreviousPageText, _CurrentPageIndex == 0 ? "disabled" : ""); } // Generate begining edge entries - The first EdgeEntriesCount of page links will be generated if (start > 0 && EdgeEntriesCount > 0) { //till where the edge entries created int edgeEnd = Math.Min(EdgeEntriesCount, start); for (int i = 0; i < edgeEnd; i++) { CreateButton(i, (i + 1).ToString(), ""); } //if there is a gap between edge entries and start,, ellipse text will be shown bw them if (EdgeEntriesCount < start && EllipseText.Length > 0) { CreateLabel(EllipseText, "plain"); } } // Generate interval links - the pagination links based on DisplayEntriesCount will generated here //links will be printed from the calculated start and end values for (int i = start; i < end; i++) { CreateButton(i, (i + 1).ToString(), ""); } // Generate ending edge entries - The final EdgeEntriesCount of page links will be generated if (end < np && EdgeEntriesCount > 0) { //if there is a gap between end link and edge entries the EllipseText will be shown if (np - EdgeEntriesCount > end && EllipseText.Length > 0) { CreateLabel(EllipseText, "plain"); } //from where the edge entries should start int begin = Math.Max(np - EdgeEntriesCount, end); for (int i = begin; i < np; i++) { CreateButton(i, (i + 1).ToString(), ""); } } // Finish the pagination with 'Next' Link if (NextPageText.Length > 0) { CreateButton(_CurrentPageIndex + 1, NextPageText, _CurrentPageIndex == end - 1 ? "disabled" : ""); } }
//create the pagination as Hyperlinks private void CreateHyperLinkPagination() { string ellipses = "<li class=\"plain\">" + EllipseText + "</li>"; //this string builder will hold the pagination string and later we will add this to a div System.Text.StringBuilder sb = new System.Text.StringBuilder(); //finidng the central postion of display entries. The current page will be shown in the center int ne_half = int.Parse(Math.Ceiling(decimal.Parse(DisplayEntriesCount.ToString()) / 2).ToString()); //retrieving the number of pages int np = TotalPages(); int upper_limit = np - DisplayEntriesCount; //finding the start position int start = _CurrentPageIndex > ne_half?Math.Max(Math.Min(_CurrentPageIndex - ne_half, upper_limit), 0) : 0; //finding the end position int end = _CurrentPageIndex > ne_half?Math.Min(_CurrentPageIndex + ne_half, np) : Math.Min(DisplayEntriesCount, np); // Begin by creating the 'Previous' Link if (PreviousPageText.Length > 0) { sb.Append(CreateLink(_CurrentPageIndex - 1, PreviousPageText, _CurrentPageIndex == 0 ? "disabled" : "")).Append(System.Environment.NewLine); } // Generate begining edge entries - The first EdgeEntriesCount of page links will be generated if (start > 0 && EdgeEntriesCount > 0) { //till where the edge entries created int edgeEnd = Math.Min(EdgeEntriesCount, start); for (int i = 0; i < edgeEnd; i++) { sb.Append(CreateLink(i, (i + 1).ToString(), "")).Append(System.Environment.NewLine); } //if there is a gap between edge entries and start,, ellipse text will be shown bw them if (EdgeEntriesCount < start && EllipseText.Length > 0) { sb.Append(ellipses).Append(System.Environment.NewLine); } } // Generate interval links - the pagination links based on DisplayEntriesCount will generated here //links will be printed from the calculated start and end values for (int i = start; i < end; i++) { sb.Append(CreateLink(i, (i + 1).ToString(), "")).Append(System.Environment.NewLine); } // Generate ending edge entries - The final EdgeEntriesCount of page links will be generated if (end < np && EdgeEntriesCount > 0) { //if there is a gap between end link and edge entries the EllipseText will be shown if (np - EdgeEntriesCount > end && EllipseText.Length > 0) { sb.Append(ellipses).Append(System.Environment.NewLine); } //from where the edge entries should start int begin = Math.Max(np - EdgeEntriesCount, end); for (int i = begin; i < np; i++) { sb.Append(CreateLink(i, (i + 1).ToString(), "")).Append(System.Environment.NewLine); } } // Finish the pagination with 'Next' Link if (NextPageText.Length > 0) { sb.Append(CreateLink(_CurrentPageIndex + 1, NextPageText, _CurrentPageIndex == end - 1 ? "disabled" : "")).Append(System.Environment.NewLine); } pnlPager.InnerHtml = sb.ToString(); }