asp.net Linq TO Sql 分頁方法
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="replist">控件ID</param>
/// <param name="DataSource">數(shù)據(jù)源</param>
/// <param name="IndexPage">當(dāng)前頁</param>
/// <param name="PageSize">每頁數(shù)據(jù)條數(shù)</param>
/// <param name="PageParemart">頁面搜索參數(shù) 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)//數(shù)據(jù)源無數(shù)據(jù)
{
rtnStr = string.Empty;
}
else
{
int yutemp = sourceCount % PageSize;
int pagecounts = (yutemp == 0) ? (sourceCount / PageSize) : (sourceCount / PageSize + 1);//總頁數(shù)
rtnStr = " <div style='width:100%;'><div style=' float:left;'>頁次:" + IndexPage + "頁/" + pagecounts + "頁,共" + sourceCount + "條記錄</div> ";
if (pagecounts == 1) //總共一頁數(shù)據(jù)
{
replist.DataSource = DataSource;
rtnStr += "[首頁] [上一頁] [下一頁] [尾頁] ";
}
else
{
rtnStr += "<div style=' float:right;'>";
if (IndexPage == 1)//首頁
{
replist.DataSource = DataSource.Take(PageSize);
rtnStr += "[首頁] [上一頁] <a href='?page=" + (IndexPage + 1) + PageParemart + "'>[下一頁]</a> <a href='?page=" + (pagecounts) + PageParemart + "'>[尾頁]</a> ";
}
else
{
replist.DataSource = DataSource.Skip((IndexPage - 1) * PageSize).Take(PageSize);
if (IndexPage == pagecounts)//末頁
{
rtnStr += "<a href='?page=1" + PageParemart + "'>[首頁]</a> <a href='?page=" + (IndexPage - 1) + PageParemart + "'>[上一頁]</a> [下一頁] [尾頁] ";
}
else
{
rtnStr += "<a href='?page=1" + PageParemart + "'>[首頁]</a> <a href='?page=" + (IndexPage - 1) + PageParemart + "'>[上一頁]</a> <a href='?page=" + (IndexPage + 1) + PageParemart + "'>[下一頁]</a> <a href='?page=" + (pagecounts) + PageParemart + "'>[尾頁]</a> ";
}
}
rtnStr += "</div></div>";
}
replist.DataBind();
}
return rtnStr;
}
頁面調(diào)用
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;
}
}
- asp.net使用LINQ to SQL連接數(shù)據(jù)庫及SQL操作語句用法分析
- asp.net中一個(gè)linq分頁實(shí)現(xiàn)代碼
- asp.net中通過ALinq讓Mysql操作變得如此簡單
- asp.net 根據(jù)漢字的拼音首字母搜索數(shù)據(jù)庫(附 LINQ 調(diào)用方法)
- asp.net Linq to Xml學(xué)習(xí)筆記
- asp.net LINQ中數(shù)據(jù)庫連接字符串的問題
- asp.net Linq To Xml上手Descendants、Elements遍歷節(jié)點(diǎn)
- .NET 9 中 LINQ 新增功能實(shí)現(xiàn)過程
相關(guān)文章
relaxlife.net發(fā)布一個(gè)自己開發(fā)的中文分詞程序
relaxlife.net發(fā)布一個(gè)自己開發(fā)的中文分詞程序...2007-03-03
使用.Net實(shí)現(xiàn)多線程經(jīng)驗(yàn)總結(jié)
這篇文章主要介紹了使用.Net實(shí)現(xiàn)多線程經(jīng)驗(yàn)總結(jié),需要的朋友可以參考下2014-12-12
Web.config 和 App.config 的區(qū)別分析
Web.config 和 App.config 的區(qū)別分析,需要的朋友可以參考一下2013-05-05
數(shù)據(jù)庫 數(shù)據(jù)類型float到C#類型decimal, float數(shù)據(jù)類型轉(zhuǎn)化無效
數(shù)據(jù)庫 數(shù)據(jù)類型float到C#類型decimal, float數(shù)據(jù)類型轉(zhuǎn)化無效的解決方法2009-07-07
GridView使用CommandField刪除列實(shí)現(xiàn)刪除時(shí)提示確認(rèn)框
在.net2005提供的GridView中我們可以直接添加一個(gè)CommandField刪除列完后在它的RowDeleting事件中完成刪除2013-09-09
.Net中如何操作IIS的虛擬目錄原理分析及實(shí)現(xiàn)方案
編程控制IIS實(shí)際上很簡單,和ASP一樣,.Net中需要使用ADSI來操作IIS,但是此時(shí)我們不再需要GetObject這個(gè)東東了,因?yàn)镹et為我們提供了更加強(qiáng)大功能的新東東2012-12-12
.net任務(wù)調(diào)度框架FluentScheduler簡介
這篇文章介紹了.net任務(wù)調(diào)度框架FluentScheduler,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07
XmlReader 讀取器讀取內(nèi)存流 MemoryStream 的注意事項(xiàng)
XmlReader 讀取器讀取內(nèi)存流 MemoryStream 的注意事項(xiàng)...2007-04-04

