private static List <PagelinkItem> GenerateLinkItems(int currentPage, int totalPages) { var pageLinks = new List <PagelinkItem>(); var prev = new PagelinkItem { Text = "prev", CssClass = "previous" }; if (currentPage != 1) { prev.Pagenumber = currentPage - 1; } pageLinks.Add(prev); int previousPageNumber = 0; foreach (var pageNumber in GenerateNumbers(currentPage, totalPages)) { if (previousPageNumber + 1 < pageNumber || previousPageNumber - 1 > pageNumber) { pageLinks.Add(new PagelinkItem { Text = "...", CssClass = "dots" }); } previousPageNumber = pageNumber; var page = new PagelinkItem { Text = Convert.ToString(pageNumber), CssClass = "number currentPage" }; if (pageNumber != currentPage) { page.Pagenumber = pageNumber; page.CssClass = "number"; } pageLinks.Add(page); } var next = new PagelinkItem { Text = "next", CssClass = "next" }; if (currentPage != totalPages) { next.Pagenumber = currentPage + 1; } pageLinks.Add(next); return(pageLinks); }
private static List<PagelinkItem> GenerateLinkItems(int currentPage, int totalPages) { var pageLinks = new List<PagelinkItem>(); var prev = new PagelinkItem { Text = "prev", CssClass = "previous" }; if (currentPage != 1) { prev.Pagenumber = currentPage - 1; } pageLinks.Add(prev); int previousPageNumber = 0; foreach (var pageNumber in GenerateNumbers(currentPage, totalPages)) { if (previousPageNumber + 1 < pageNumber || previousPageNumber - 1 > pageNumber) { pageLinks.Add(new PagelinkItem { Text = "...", CssClass = "dots" }); } previousPageNumber = pageNumber; var page = new PagelinkItem { Text = Convert.ToString(pageNumber), CssClass = "number currentPage" }; if (pageNumber != currentPage) { page.Pagenumber = pageNumber; page.CssClass = "number"; } pageLinks.Add(page); } var next = new PagelinkItem { Text = "next", CssClass = "next" }; if (currentPage != totalPages) { next.Pagenumber = currentPage + 1; } pageLinks.Add(next); return pageLinks; }