ASP.NET中repeater分页功能点击下一页没有反应,谁知道解答一下,谢谢,第一次发

qq_29568523 2018-04-15 05:33:14
后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Security;
public partial class bbb : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPage.Text = "1";
PagingRepeater();
}
}
public void PagingRepeater()
{

string sqlStr = "select id,title from gonggao1";
DataSet ds = SqlHelper.GetDataSet(sqlStr);
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
lblTolal.Text = pds.Count.ToString();
pds.CurrentPageIndex = Convert.ToInt32(this.lblPage.Text) - 1;
Repeater1.DataSource = pds;
lblCountPage.Text = pds.PageCount.ToString();
lblPage.Text = (pds.CurrentPageIndex + 1).ToString();
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
LinkButton3.Enabled = true;
LinkButton4.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = false;
}
if(pds.CurrentPageIndex == pds.PageCount - 1)
{
LinkButton3.Enabled = false;
LinkButton4.Enabled = false;
}
Repeater1.DataBind();
}
前台代码
<form id="form1" runat="server">
<div>
新闻列表
</div>
<div>
<table class="auto-style1">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" EnableTheming="True">
<ItemTemplate>
<tr>
<td>
<a href="NewsShow.aspx?id=<%#Eval("id") %>">
<%#Eval("title") %>
</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
<div>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" OnClick="LinkButton4_Click">尾页</asp:LinkButton>
第<asp:Label ID="lblPage" runat="server" Text="Lable"></asp:Label>页/共
<asp:Label ID="lblCountPage" runat="server" Text="Lable"></asp:Label>页 共
<asp:Label ID="lblTolal" runat="server">条新闻</asp:Label>
</div>
</form>
...全文
634 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
真相重于对错 2018-04-15
  • 打赏
  • 举报
回复
好久没用过asp.net了,感觉是你点击后应该重新绑定一下数据源
  • 打赏
  • 举报
回复
贴出编译器编译结果截图。

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧