Copy codeThe Code is as follows:
/// <Summary>
/// Paging Link
/// </Summary>
/// <Param name = "pageSize"> </param>
/// <Param name = "recordCount"> </param>
/// <Param name = "currentPage"> </param>
/// <Param name = "prev"> number displayed before the current page </param>
/// <Param name = "next"> number displayed after the current page </param>
/// <Returns> </returns>
Public string PageLink (int pageSize, int recordCount, int currentPage, int prev, int next)
{
Int pageCount = recordCount % pageSize = 0? (RecordCount/pageSize): (int) Math. Ceiling (double) recordCount/pageSize ));
StringBuilder sb = new StringBuilder ();
If (currentPage> 1 & recordCount> 1)
{
Sb. Append ("<a href = \"? Page = ");
Sb. Append (currentPage-1). ToString ());
Sb. Append ("\"> previous page </a> ");
}
If (currentPage> prev + 1)
Sb. Append ("<a href = \"? Page = 1 \ "> 1 </a> ...");
If (currentPage <prev)
Next = next + prev-currentPage + 1;
If (next> pageCount-currentPage)
Prev = prev + next-(pageCount-currentPage );
For (int I = 1; I <= pageCount; I ++)
{
If (I = currentPage)
{
Sb. Append ("<a href = \"? Page = "+ I +" \ "class = \" current \ "> <font color = \" red \ ">" + I + "</font> </a> ");
}
Else
{
If (I> (currentPage-prev-1) & I <(currentPage + next + 1 ))
{
Sb. Append ("<a href = \"? Page = "+ I +" \ ">" + I + "</a> ");
}
}
}
If (currentPage <pageCount-next)
Sb. Append ("... <a href = \"? Page = "+ pageCount. ToString () +" \ ">" + pageCount. ToString () + "</a> ");
If (currentPage <pageCount)
Sb. Append ("<a href = \"? Page = "+ (currentPage + 1). ToString () +" \ "> next page </a> ");
Return sb. ToString ();
}