asp.net LINQ to Sql Paging method _ Practical Tips

Source: Internet
Author: User
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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.