weixin_41988954 2019-06-05 22:08 采纳率: 0%
浏览 640

有人帮我看一下这段分页代码为什么只显示第一页的数据吗

public partial class BookList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataList1.DataSource = DBHelper.GetDataSet("select * from BookInfo").DefaultView;
DataList1.DataBind();
}
Paging();
}

protected void Paging()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = DBHelper.GetDataSet("select * from BookInfo").DefaultView;//取数据
pds.AllowPaging = true;//允许分页
pds.PageSize = 3; //设置页面大小

Label lbl = ((Label)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lblTotalPage"));
string str = lbl.Text = pds.PageCount.ToString();
pds.CurrentPageIndex = 0;

((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkFirst")).Enabled = true;
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkPrevious")).Enabled = true;
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkNext")).Enabled = true;
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkLast")).Enabled = true;
//判断当前页是否为首页或者末页
if (pds.CurrentPageIndex == 0)
{
//禁用首页和上一页
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkFirst")).Enabled = false;
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkPrevious")).Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
//禁用下一页和末页
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkLast")).Enabled = false;
((LinkButton)this.DataList1.Controls[DataList1.Controls.Count - 1].FindControl("lnkNext")).Enabled = false;
}

DataList1.DataSource = pds;
DataList1.DataBind();
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-06-06 10:38
    关注

    pds.CurrentPageIndex = 0;
    你代码中没有从页面返回页码,而是直接为0,那当然每次都是第一页了
    正确的做法是,要在页码链接里带上页码,在你这里代码里从querystring读取当前页码

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM