就分页的技术来看,无非是分两种:

一。通过存储过程来实现

     此点,暂时不讲,因为网上文章很多,迟一下再发表我的意见。

二。通过页面代码来实现

    我之前在网上看到一个文章,说的是为DATALIST分页,用的技术是viewstate保存分页信息,然后再通过这个信息(如当前是第几页,每页多少等)来实现分页。虽然能实现功能,不过,这一点明显是多此一举,究其原因,是由于没有深入认识。NET。其实。NET本身有一个PagedDataSource,它是从GridView里分离出来的分页代码封装,可以轻松实现分页。下面,就以DATALIST作为例子,看一下,他是怎样使用的:

用PagedDataSource实现分页       
用PagedDataSource实现分页以上代码省略
用PagedDataSource实现分页 DataSet ds = db.ExecuteDataSet(dbc);
用PagedDataSource实现分页        PagedDataSource pds = new PagedDataSource();//初始化分页源
用PagedDataSource实现分页        pds.DataSource = ds.Tables[0].DefaultView;
用PagedDataSource实现分页        pds.PageSize = 15;//每页显示的记录数
用PagedDataSource实现分页    
用PagedDataSource实现分页        pds.AllowPaging = true;//是否分页
用PagedDataSource实现分页
用PagedDataSource实现分页
用PagedDataSource实现分页        pds.CurrentPageIndex = pageid - 1;//当前页数,因为从0开始,所以接收到的数减1
用PagedDataSource实现分页
用PagedDataSource实现分页        DataList1.DataSource = pds;//绑定数据源
用PagedDataSource实现分页        DataList1.DataBind();//绑定数据
用PagedDataSource实现分页
用PagedDataSource实现分页        if (pds.IsFirstPage)
用PagedDataSource实现分页
用PagedDataSource实现分页            hy1.Visible = false;
用PagedDataSource实现分页        if (pds.IsLastPage)
用PagedDataSource实现分页            hy2.Visible = false;
用PagedDataSource实现分页        int pg;
用PagedDataSource实现分页        int showp = 10;//显示多少页
用PagedDataSource实现分页
用PagedDataSource实现分页
用PagedDataSource实现分页       
用PagedDataSource实现分页
用PagedDataSource实现分页        string pgstr;
用PagedDataSource实现分页        pgstr = " ";//分页显示代码
用PagedDataSource实现分页        int startp;//开始页数
用PagedDataSource实现分页        int nowp;
用PagedDataSource实现分页        nowp = pds.CurrentPageIndex + 1;
用PagedDataSource实现分页        int totalp;
用PagedDataSource实现分页        totalp = pds.PageCount;//得到总页数
用PagedDataSource实现分页        //   startp = 1;
用PagedDataSource实现分页
用PagedDataSource实现分页        if (nowp % showp == 0)//是否等于上限
以下代码省略

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-06-01
  • 2021-07-05
  • 2021-10-02
猜你喜欢
  • 2021-08-10
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2022-01-13
  • 2022-12-23
相关资源
相似解决方案