时间:2021-05-26
分页方法
复制代码 代码如下:
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="replist">控件ID</param>
/// <param name="DataSource">数据源</param>
/// <param name="IndexPage">当前页</param>
/// <param name="PageSize">每页数据条数</param>
/// <param name="PageParemart">页面搜索参数 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)//数据源无数据
{
rtnStr = string.Empty;
}
else
{
int yutemp = sourceCount % PageSize;
int pagecounts = (yutemp == 0) ? (sourceCount / PageSize) : (sourceCount / PageSize + 1);//总页数
rtnStr = " <div style='width:100%;'><div style=' float:left;'>页次:" + IndexPage + "页/" + pagecounts + "页,共" + sourceCount + "条记录</div> ";
if (pagecounts == 1) //总共一页数据
{
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;
}
页面调用
复制代码 代码如下:
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;
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设
64位ASP.Net已注册。需要32位ASP.Net才能安装MicrosoftReportingServices2005(32位)。安装SQL2005时出现这个
本文实例讲述了asp.net中的GridView分页问题。分享给大家供大家参考。具体分析如下:在ASP.NET中,经常会使用到GridView的分页,一般情况下
一、AspNetPager分页控件分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net1.1)
本文实例讲述了asp.net实现简单分页的方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下://////分页内容//////页面大小///页面数量