I have a set of results that I would like to be paginated for a page on a c#, dotnet website.
The first set contains only 22 results (Because there will be something else visually taking up the space of two of these results on the first page's layout).
each subsequent set contains 24 results.
Id like to generate a list URLs that look like this:-
"/result-set/1/0/21",
"/result-set/2/22/46",
"/result-set/3/47/71"
And so on... Where the first number represents the page number, the second a start index and the third an end index that doesn't exceed the total number of records.
I can seem to get the math right and I've made it harder for myself with the first set having a smaller amount in it.
One approach is to skip the first 22 results and to manually add that to the top of the list.
Perhaps if someone could recommend a good library? because I'm possibly re-inventing the wheel here. The ones that I have found seem to be integrated with Entity Framework.
Make a function to calculate the indexes, with page No. as input.
using System;
public class Program
{
public static (int, int) GetIndexes(int pageNum) {
if (pageNum <= 1)
return (0, 21);
int toAdd = (pageNum-2) * 25;
return (22 + toAdd, 46 + toAdd);
}
public static void Main() {
Console.WriteLine(GetIndexes(1));
Console.WriteLine(GetIndexes(2));
Console.WriteLine(GetIndexes(3));
Console.WriteLine(GetIndexes(4));
}
}