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

本文介绍了一个使用ASP.NET实现的简单新闻列表分页显示功能。通过后台代码中的SQL查询从数据库中获取新闻数据,并利用PagedDataSource进行分页处理,最后在前端页面展示新闻标题链接及分页导航按钮。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

后台代码

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值