Adaptive/dynamic page numbering in c#

If you need to show many results (tens, hundreds or thousands), in a paged manner, you won’t want to display links to all those pages. I looked online for some c# that would adapt the number of page links shown to with the number of pages returned, but found nothing.