C# 分页类
<asp:RepeaterID="shuchu"runat="server"></asp:Repeater>控件完整类,以及调用。...
<asp:Repeater ID="shuchu" runat="server"> </asp:Repeater>控件
完整类,以及调用。 展开
完整类,以及调用。 展开
5个回答
展开全部
/// <summary>
/// 分页
/// </summary>
/// <param name="pageCount">总页数</param>
/// <param name="recordCount">总记录数</param>
/// <param name="Curpage">当前页</param>
/// <returns>返回分页HTML</returns>
public static string GetButtonStatus(int pageCount, int recordCount, int Curpage)
{
string str = string.Empty;
StringBuilder sb = new StringBuilder();
if (Curpage == 1)
{
sb.Append("<span class=\"noPage\">首页</span> ");
sb.Append("<span class=\"noPage\">上一页</span> ");
}
else
{
sb.Append("<a href=\"ActionCenterList.aspx?pageindex=1\" title=\"转至第1页\" class=\"a1\">首页</a> ");
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\" class=\"a1\">上一页</a> ", Curpage - 1, Curpage - 1);
}
if (pageCount <= 9)
{
for (int i = 1; i <= pageCount; i++)
{
if (i == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", i);
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", i, i);
}
}
}
else
{
if (Curpage <= 5)
{
for (int i = 1; i <= 9; i++)
{
if (i == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", i);
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", i, i);
}
}
}
else if (Curpage > (pageCount - 5))
{
for (int i = 1; i <= 9; i++)
{
if ((pageCount - 9 + i) == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", (pageCount - 9 + i));
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", (pageCount - 9 + i), (pageCount - 9 + i));
}
}
}
else
{
for (int i = 1; i <= 9; i++)
{
if ((Curpage - 5 + i) == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", (Curpage - 5 + i));
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", (Curpage - 5 + i), (Curpage - 5 + i));
}
}
}
}
if (Curpage == pageCount)
{
sb.Append("<span class=\"noPage\">下一页</span> ");
sb.Append("<span class=\"noPage\">末页</span> ");
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\" class=\"a1\">下一页</a> ", Curpage+1, Curpage + 1);
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\" class=\"a1\">末页</a> ", pageCount, pageCount);
}
return sb.ToString();
}
/// 分页
/// </summary>
/// <param name="pageCount">总页数</param>
/// <param name="recordCount">总记录数</param>
/// <param name="Curpage">当前页</param>
/// <returns>返回分页HTML</returns>
public static string GetButtonStatus(int pageCount, int recordCount, int Curpage)
{
string str = string.Empty;
StringBuilder sb = new StringBuilder();
if (Curpage == 1)
{
sb.Append("<span class=\"noPage\">首页</span> ");
sb.Append("<span class=\"noPage\">上一页</span> ");
}
else
{
sb.Append("<a href=\"ActionCenterList.aspx?pageindex=1\" title=\"转至第1页\" class=\"a1\">首页</a> ");
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\" class=\"a1\">上一页</a> ", Curpage - 1, Curpage - 1);
}
if (pageCount <= 9)
{
for (int i = 1; i <= pageCount; i++)
{
if (i == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", i);
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", i, i);
}
}
}
else
{
if (Curpage <= 5)
{
for (int i = 1; i <= 9; i++)
{
if (i == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", i);
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", i, i);
}
}
}
else if (Curpage > (pageCount - 5))
{
for (int i = 1; i <= 9; i++)
{
if ((pageCount - 9 + i) == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", (pageCount - 9 + i));
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", (pageCount - 9 + i), (pageCount - 9 + i));
}
}
}
else
{
for (int i = 1; i <= 9; i++)
{
if ((Curpage - 5 + i) == Curpage)
{
sb.AppendFormat("<span class=\"curPage\" data-key=\"1\">{0}</span> ", (Curpage - 5 + i));
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\">{1}</a> ", (Curpage - 5 + i), (Curpage - 5 + i));
}
}
}
}
if (Curpage == pageCount)
{
sb.Append("<span class=\"noPage\">下一页</span> ");
sb.Append("<span class=\"noPage\">末页</span> ");
}
else
{
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\" class=\"a1\">下一页</a> ", Curpage+1, Curpage + 1);
sb.AppendFormat("<a href=\"ActionCenterList.aspx?pageindex={0}\" title=\"转至第{1}页\" class=\"a1\">末页</a> ", pageCount, pageCount);
}
return sb.ToString();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单分页的话,用PagedDataSource 类就可以了
void bindData(Repeater shuchu, int page){
DataSet ds = new DataSet();// 这里获取数据填充DataSet
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = page;// 这里设置当前要显示第几页
shuchu.DataSource = pds;
shuchu.DataBind();
}
void bindData(Repeater shuchu, int page){
DataSet ds = new DataSet();// 这里获取数据填充DataSet
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = page;// 这里设置当前要显示第几页
shuchu.DataSource = pds;
shuchu.DataBind();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议你可以用这样的方式
前台页面引用:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
前台内容:
<div class="list" style="width:600px;">
<ul>
<asp:Repeater ID="List" runat="server">
<ItemTemplate>
<li>
<h1>
<a href="ArticlePage.aspx?type=2&id=<%#Eval("id") %>" title="<%#Eval("Title") %>">
<%#Eval("title")%></a></h1>
<h2>
<%#Eval("dateUploading", "{0:yyyy-MM-dd}")%></h2>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<div style="text-align:center;">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanging="AspNetPager1_PageChanging"
Width="95%" PageSize="2" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页"
PrevPageText="上一页" >
</webdiyer:AspNetPager>
</div>
</div>
后台
protected void Page_Load(object sender, EventArgs e)
{
BinMain();
}
protected void BinMain()
{
if (vip_id != null && vip_id != "")
{
Session["vip_id"] = vip_id;
DataSet dsArticle1 = B_ArticleIssue.Article_Query(vip_id);//这个是获取一共有多少条记录的
DataSet dsArticle = B_ArticleIssue.Article_Query(vip_id, AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);//这个是个子查询,获得的数据集绑定在控件上
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;//设置允许分页
pds.DataSource = dsArticle1.Tables[0].DefaultView;//设置分页的数据源
AspNetPager1.RecordCount = pds.Count;//AspNetPager1.RecordCount =ds.Tables[0].DefaultView.Count;等价//获取数据的条数
//pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//设置当前页的索引
pds.PageSize = AspNetPager1.PageSize;//设置每页显示的页数
this.List.DataSource = dsArticle;
this.List.DataBind();
}
}
protected void AspNetPager1_PageChanging(object src,Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BinMain();
}
前台页面引用:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
前台内容:
<div class="list" style="width:600px;">
<ul>
<asp:Repeater ID="List" runat="server">
<ItemTemplate>
<li>
<h1>
<a href="ArticlePage.aspx?type=2&id=<%#Eval("id") %>" title="<%#Eval("Title") %>">
<%#Eval("title")%></a></h1>
<h2>
<%#Eval("dateUploading", "{0:yyyy-MM-dd}")%></h2>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<div style="text-align:center;">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanging="AspNetPager1_PageChanging"
Width="95%" PageSize="2" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页"
PrevPageText="上一页" >
</webdiyer:AspNetPager>
</div>
</div>
后台
protected void Page_Load(object sender, EventArgs e)
{
BinMain();
}
protected void BinMain()
{
if (vip_id != null && vip_id != "")
{
Session["vip_id"] = vip_id;
DataSet dsArticle1 = B_ArticleIssue.Article_Query(vip_id);//这个是获取一共有多少条记录的
DataSet dsArticle = B_ArticleIssue.Article_Query(vip_id, AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);//这个是个子查询,获得的数据集绑定在控件上
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;//设置允许分页
pds.DataSource = dsArticle1.Tables[0].DefaultView;//设置分页的数据源
AspNetPager1.RecordCount = pds.Count;//AspNetPager1.RecordCount =ds.Tables[0].DefaultView.Count;等价//获取数据的条数
//pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//设置当前页的索引
pds.PageSize = AspNetPager1.PageSize;//设置每页显示的页数
this.List.DataSource = dsArticle;
this.List.DataBind();
}
}
protected void AspNetPager1_PageChanging(object src,Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BinMain();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我们项目都是repeater的输出,你要分页我把分页方法类给你吧,不过粘贴出来老多老多了。有邮箱我给你发一个过去。记得加分哦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你给个邮箱吧!要是列出来太多了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询