diff --git a/src/Framework/Core/Controls/Options/PagingOptions.cs b/src/Framework/Core/Controls/Options/PagingOptions.cs index 9a626f53fe..83e009520e 100644 --- a/src/Framework/Core/Controls/Options/PagingOptions.cs +++ b/src/Framework/Core/Controls/Options/PagingOptions.cs @@ -107,8 +107,10 @@ public virtual IList GetNearPageIndexes() /// protected virtual IList GetDefaultNearPageIndexes(int distance) { - var firstIndex = Math.Max(PageIndex - distance, 0); - var lastIndex = Math.Min(PageIndex + distance + 1, PagesCount); + var count = this.PagesCount; + var index = Math.Max(0, Math.Min(count - 1, PageIndex)); // clamp index to be a valid page + var firstIndex = Math.Max(index - distance, 0); + var lastIndex = Math.Min(index + distance + 1, count); return Enumerable .Range(firstIndex, lastIndex - firstIndex) .ToList();