The following is a self-compiled Asp.net paging method. I hope to give you more instructions.
Public static stringbuilder pagebtn (INT currentpage, int numinoneline, string URL, pageddatasource PPS) // returns the index string. numinoneline indicates the number of indexes per row, and currentpage indicates the current page;
{
Stringbuilder sb = new stringbuilder ();
Int currentline; // The current index row.
If (currentpage % numinoneline! = 0) // determines whether the current page is an integer multiple of the number of indexes in each row;
{
Currentline = currentpage/numinoneline + 1;
}
Else
{
Currentline = currentpage/numinoneline;
}
// Add the connection of the last index row
If (currentline = 1)
{
SB. append ("<& nbsp ");
}
Else
{
SB. append ("<a href = '");
SB. append (URL );
SB. append ("? Currentpage = ");
SB. append (convert. tostring (currentLine-1) * numinoneline ));
SB. append ("'><</A> & nbsp ");
}
// Add a page number index
For (INT I = 1; I <= numinoneline; I ++)
{
// <A href = "datalist. aspx" style = "color: Red"> [] </a>
If (currentline-1) * numinoneline + I <= PPS. pagecount) // determines whether the page number is out of bounds;
{
If (currentline-1) * numinoneline + I = currentpage) // you can check whether the index page number is the current page.
{
SB. append ("& nbsp <font style = 'color: red; text-Decoration: none; '> ");
SB. append (currentpage. tostring ());
SB. append ("</font> & nbsp ");
}
Else
{
SB. append ("<a href = '");
SB. append (URL );
SB. append ("? Currentpage = ");
SB. append (convert. tostring (currentline-1) * numinoneline + I ));
SB. append ("'> [");
SB. append (convert. tostring (currentline-1) * numinoneline + I ));
SB. append ("] </a> & nbsp ");
}
}
}
Int totalline; // defines the total number of indexed rows.
If (PPS. pagecount % numinoneline! = 0) // determines whether the total number of pages is an integer multiple of the number of indexes in each row;
{
Totalline = PPS. pagecount/numinoneline + 1;
}
Else
{
Totalline = PPS. pagecount/numinoneline;
}
// Add the next index row
If (currentline = totalline)
{
SB. append ("> ");
}
Else
{
SB. append ("<a href = '");
SB. append (URL );
SB. append ("? Currentpage = ");
SB. append (convert. tostring (currentline * numinoneline + 1 ));
SB. append ("'>></A> ");
}
Return Sb;
}