我写的分页,怎怎么显示的还是所有的

aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="Test.Main" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




<br> a.LinkButtonDefault{text-align:center;text-decoration:none;margin-right:1px;padding:2px 4px;}<br> a.LinkButtonBlue{background: #ebebeb;text-align:center;text-decoration:none;margin-right:1px;padding:2px 4px;}<br> a.LinkButtonYellow { background-color:#ccc; color:#000fff; font-weight:bold;text-align:center;text-decoration:none;margin-right:1px;padding:2px 4px;}<br>





















<%--//--%>



商品ID 名称 单价 单位 操作
<%# Eval("ID") %> <%# Eval("ShopName")%> <%# Eval("Price")%> <%# Eval("Desc")%> >加入购物车/asp:LinkButton


/asp:Repeater



/asp:Label页:
首页/asp:LinkButton
上一页/asp:LinkButton


CssClass='' CommandArgument='<%# Container.DataItem %>'>
/asp:LinkButton

/asp:Repeater
下一页/asp:LinkButton
尾页/asp:LinkButton




aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;

namespace Test
{
public partial class Main : System.Web.UI.Page
{
ShopBLL shopBll = new ShopBLL();
private int m_PageSize;
public int PageSize //每页显示记录数
{
set
{
m_PageSize = value;
}
get
{
if (m_PageSize.Equals(0))
{
m_PageSize = 10;
}
return m_PageSize;
}
}
private int m_PageIndex;
public int PageIndex //当前页页码
{
set
{
m_PageIndex = value;
}
get
{
if (m_PageIndex.Equals(0))
{
m_PageIndex = 1;
}
return m_PageIndex;
}
}
public int TotalItemCount //记录总数
{
set;
private get;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindPagingHelperControl();
}
}

    protected void lbtnPage_Click(object sender, EventArgs e)
    {
        LinkButton lbtn = sender as LinkButton;
        ReBindData(int.Parse(lbtn.CommandArgument));
    }


    #region 公共方法

    #endregion

    #region 私有方法
    private void BindPageNum(int totalPages)
    {
        int startPageIndex = 1, endPageIndex = 10;
        if (totalPages < endPageIndex)
        {
            endPageIndex = totalPages;
        }
        else
        {
            startPageIndex = (PageIndex > 5) ? PageIndex - 5 : startPageIndex;
            int result = (startPageIndex + 9) - totalPages;
            if (result > 0)
            {
                endPageIndex = totalPages;
                startPageIndex -= result;
            }
            else
            {
                endPageIndex = startPageIndex + 9;
            }
        }
        BindPageNum(startPageIndex, endPageIndex);
    }
    private void BindPageNum(int startPageIndex, int endPageIndex)
    {
        int[] pages = new int[endPageIndex - startPageIndex + 1];
        int index = 0;
        for (int i = startPageIndex; i <= endPageIndex; i++)
        {
            pages[index] = i;
            index++;
        }
        rptPageNumber.DataSource = pages;
        rptPageNumber.DataBind();
    }
    private void BindPagingHelperControl()
    {
        DataTable dt = new DataTable();
        dt = shopBll.GetShopALL();
        repList.DataSource = dt;
        repList.DataBind();
        TotalItemCount = dt.Rows.Count;
        int totalPages = (TotalItemCount % PageSize) == 0 ? TotalItemCount / PageSize : TotalItemCount / PageSize + 1;
        //显示
        lbTotalPages.Text = totalPages.ToString();
        BindPageNum(totalPages);
        //使能
        lbtnFirstPage.Enabled = PageIndex > 1;
        lbtnPrevPage.Enabled = PageIndex > 1;
        lbtnLastPage.Enabled = PageIndex < totalPages;
        lbtnNextPage.Enabled = PageIndex < totalPages;
        //命令
        lbtnFirstPage.CommandArgument = "1";
        lbtnPrevPage.CommandArgument = (PageIndex - 1).ToString();
        lbtnNextPage.CommandArgument = (PageIndex + 1).ToString();
        lbtnLastPage.CommandArgument = totalPages.ToString();
    }
    private void ReBindData(int pageIndex)
    {
        PageIndex = pageIndex;
        OnPageIndexChanged(new EventArgs());
        BindPagingHelperControl();
    }
    #endregion

    #region 事件
    public delegate void PageIndexChangedEventHandler(object sender, EventArgs e);
    public event PageIndexChangedEventHandler PageIndexChanged;
    protected virtual void OnPageIndexChanged(EventArgs e)
    {
        PageIndexChangedEventHandler handler = PageIndexChanged;
        if (handler != null)
        {
            handler(this, e);
        }
    }
    #endregion
}

}

3个回答

要看ReBindData你怎么写的,参数有没有传对,它有没有分页的功能

分页应该分出来,就是显示的时候条数有问题

分页应该分出来,就是显示的时候条数有问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐