ASP.NET中repeater分页功能点击下一页没有反应,谁知道解答一下,谢谢,第一次发
后台代码
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>