Paging method
Copy Code code as follows:
<summary>
///
</summary>
<typeparam name= "T" ></typeparam>
<param name= "Replist" > Controls Id</param>
<param name= "DataSource" > Data source </param>
<param name= "indexpage" > Current page </param>
<param name= "PageSize" > per-page data bar </param>
<param name= "Pageparemart" > page search parameters 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)//data Source No data
{
Rtnstr = string. Empty;
}
Else
{
int yutemp = sourcecount% PageSize;
int pagecounts = (yutemp = 0)? (sourcecount/pagesize): (sourcecount/pagesize + 1);//Total pages
Rtnstr = "<div style= ' width:100%; ' ><div style= ' float:left; ' > page: "+ indexpage +" page/"+ pagecounts +" page, a total of "+ Sourcecount +" record </div>;
if (pagecounts = 1)//Total one page data
{
Replist. DataSource = DataSource;
Rtnstr + = "[first] [prev] [next] [last]";
}
Else
{
Rtnstr + = "<div style= ' float:right; ' > ";
if (indexpage = 1)//home
{
Replist. DataSource = Datasource.take (PageSize);
Rtnstr + = "[Home] [prev] <a href= '? page=" + (Indexpage + 1) + Pageparemart + "' >[next]</a> <a ' href= '? page=" + ( pagecounts) + Pageparemart + "' >[last]</a>";
}
Else
{
Replist. DataSource = Datasource.skip (IndexPage-1) * PageSize). Take (PageSize);
if (indexpage = = pagecounts)//Last
{
Rtnstr + = "<a href= '" page=1 "+ Pageparemart +" ' >[home]</a> <a '? href= "+ (page=) + IndexPage-1 + "' >[page]</a> [next] [last]";
}
Else
{
Rtnstr + = "<a href= '" page=1 "+ Pageparemart +" ' >[home]</a> <a '? href= "+ (page=) + IndexPage-1 + "' >[]</a> <a href= '? page=" + (Indexpage + 1) + Pageparemart + "' >[next page]</a> <a ' href= '? page=" + (pagecounts) + Pageparemart + "' >[last]</a>";
}
}
Rtnstr = "</div></div>";
}
Replist. DataBind ();
}
return rtnstr;
}
Page calls
Copy Code code 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;
}
}