分页方法
复制代码 代码如下:
/// <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;
}
}
复制代码 代码如下:
/// <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;
}
}
标签:
asp.net,分页
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net Linq TO Sql 分页方法”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。