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

qq_29568523 2018-04-13 08:41:34
后台代码

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>
...全文
824 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
think_m717 2018-04-20
  • 打赏
  • 举报
回复
貌似点击 需要事件代码吧?
qq_29568523 2018-04-20
  • 打赏
  • 举报
回复
写出来了,谢谢,怎样结帖
  • 打赏
  • 举报
回复
你的事件代码呢? LinkButton1_Click之类的,你贴出来的代码只有在第一次加载时才执行PagingRepeater

110,535

社区成员

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

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

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