Iverson_MVP_3 2015-05-06 03:58 采纳率: 37.5%
浏览 1636

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

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条回答

  • threenewbee 2015-05-06 04:15
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了