Paging Method
Copy codeThe Code is as follows:
/// <Summary>
///
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
/// <Param name = "replist"> Control ID </param>
/// <Param name = "DataSource"> data source </param>
/// <Param name = "IndexPage"> current page </param>
/// <Param name = "PageSize"> Number of data entries per page </param>
/// <Param name = "PageParemart"> page search parameter like & a = a & B = B </param>
/// <Returns> </returns>
Public static string ShowPage <T> (System. Web. UI. WebControls. Repeater replist, IQueryable <T> DataSource, int IndexPage, int PageSize, string PageParemart)
{
String rtnStr = "";
Int sourceCount = DataSource. Count ();
If (sourceCount = 0) // No data in the data source
{
RtnStr = string. Empty;
}
Else
{
Int yutemp = sourceCount % PageSize;
Int pagecounts = (yutemp = 0 )? (SourceCount/PageSize): (sourceCount/PageSize + 1); // total number of pages
RtnStr = "<div style = 'width: 100%; '> <div style = 'float: left;'> page times: "+ IndexPage +" Page/"+ pagecounts +" Page, total "+ sourceCount +" records </div> ";
If (pagecounts = 1) // a total of one page of data
{
Replist. DataSource = DataSource;
RtnStr + = "[homepage] [Previous Page] [Next Page] [last page]";
}
Else
{
RtnStr + = "<div style = 'float: right; '> ";
If (IndexPage = 1) // Home Page
{
Replist. DataSource = DataSource. Take (PageSize );
RtnStr + = "[homepage] [Previous Page] <a href = '? Page = "+ (IndexPage + 1) + PageParemart +" '> [Next page] </a> <a href = '? Page = "+ (pagecounts) + PageParemart +" '> [last page] </a> ";
}
Else
{
Replist. DataSource = DataSource. Skip (IndexPage-1) * PageSize). Take (PageSize );
If (IndexPage = pagecounts) // The last page
{
RtnStr + = "<a href = '? Page = 1 "+ PageParemart +" '> [homepage] </a> <a href = '? Page = "+ (IndexPage-1) + PageParemart +" '> [Previous page] </a> [Next page] [last page] ";
}
Else
{
RtnStr + = "<a href = '? Page = 1 "+ PageParemart +" '> [homepage] </a> <a href = '? Page = "+ (IndexPage-1) + PageParemart +" '> [Previous page] </a> <a href = '? Page = "+ (IndexPage + 1) + PageParemart +" '> [Next page] </a> <a href = '? Page = "+ (pagecounts) + PageParemart +" '> [last page] </a> ";
}
}
RtnStr + = "</div> ";
}
Replist. DataBind ();
}
Return rtnStr;
}
Page call
Copy codeThe Code is as follows:
Private int PageSize = 10;
Private int IndexPage = 1;
Private string PageParemart = "";
Private void Bind ()
{
Strwhere = "1 = 1" + strwhere;
Str2 = "1 = 1" + str2;
Var a = from B in datas. fav_Awards_User select B;
Label2.Text = common. PageFen. ShowPage (replist, a, this. IndexPage, this. PageSize, this. PageParemart );
If (Label2.Text = "")
{
Label1.Visible = true;
}
}