Hello its my code where I giving out paging of view:
<div style="float: right;">
<%= Html.RouteLink("<<", new { page = 1 }, new { title = "first page" })%>
<% if (this.Model.HasPreviousPage)
{%>
<%= Html.RouteLink("<", new { page = (Model.PageIndex - 1) }, new { title = "previous page"})%>
<%} %>
<%
for (int i = 1; i <= this.Model.PageIndex + 2; i++)
{ if(i <= this.Model.TotalPages){
%>
<%= Html.ActionLink(Convert.ToString(i), "Overview", new { page = i }, new { title = i + " page"})%>
<% }}%>
<% if (this.Model.HasNextPage)
{%>
<%= Html.RouteLink(">", new { page = (Model.PageIndex + 1) }, new { title = "next page"})%>
<%} %>
<%= Html.RouteLink(">>", new { page = Model.TotalPages }, new { title = "last page" })%>
</div>
it looks like this:
<< 1 2 3 > >>
I want to show always just a two pages before and after selected page. If Iam on page 4, I will see all 3 pages before like this.
<< < 1 2 3 **4** > >>
How can I do it, help me please.. i a little in stock in my mind at the moment, have no idea how to manipulate this.
my model has following data for paging:
/// <summary>
/// Gets the boolean value of previous page
/// </summary>
public bool HasPreviousPage
{
get
{
return (PageIndex > 1);
}
}
/// <summary>
/// Gets the boolean value of next page
/// </summary>
public bool HasNextPage
{
get
{
return (PageIndex + 1 <= TotalPages);
}
}
/// <summary>
/// gets total pages of overview.aspx
/// </summary>
public int TotalPages
{
get
{
return _totalPages;
}
set
{
_totalPages = value;
}
}
/// <summary>
/// gets total count
/// </summary>
public int TotalCount
{
get
{
return _totalCount;
}
set
{
_totalCount = value;
}
}
/// <summary>
/// gets actual page index
/// </summary>
public int PageIndex
{
get
{
return _pageIndex;
}
set
{
_pageIndex = value;
}
}
/// <summary>
/// gets page size
/// </summary>
public int PageSize
{
get
{
return _pageSize;
}
set
{
_pageSize = value;
}
}
PageSize = 5;
PageIndex = page;
TotalCount = Threads.Count;
TotalPages = TotalCount / PageSize;
int pageResult = 0;
for (int counter = 1; pageResult < this.TotalCount; counter++)
{
pageResult = counter * this.PageSize;
TotalPages = counter;
}
FirstThreads = new List<Thread>();
FirstThreads.AddRange(Threads.Skip<Thread>((PageIndex - 1) * PageSize).Take<Thread>(PageSize));