if (pageIndex - 1 < 0) { pageIndex = 1; } int starrow = (pageIndex - 1) * gridSize + 1; int endrow = pageIndex * gridSize;