List集合绑定AspnetPage ,List集合 里头有一些数据 需要分页但是 这个集合不是从数据库中读到的 所以 不知道怎么绑定到AspnetPage控件,如果大家有好的方法或者其他的分页方式又或者是自己写的方法 都可以,谢谢各位啦。

解决方案 »

  1.   

    http://www.webdiyer.com/AspNetPagerDemo/default.aspx
    自己找
      

  2.   

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBind();
            }
        }
        private void DataBind()
        {
            List<string> list = new List<string>();
            list.Add("1");
            list.Add("2");
            list.Add("3");
            list.Add("4");
            list.Add("5");
            list.Add("6");        this.GridView1.DataSource = GetPageList(list, 2, 2);
            this.GridView1.DataBind();
        }
        private List<string> GetPageList(List<string> list, int PageIndex, int PageSize)
        {
            if (PageIndex == 0)//如果将其全部返回
            {
                return list;
            }
            List<string> newlist = new List<string>();//新的集合
            int rowbegin = (PageIndex - 1) * PageSize;//起始行数
            int rowEnd = PageIndex * PageSize;//结束行数
            if (rowbegin >= list.Count)//如果起始行数大于总数 返回空
            {
                return newlist;
            }
            for (int i = rowbegin; i < rowEnd ; i++)
            {
                newlist.Add(list[i]);//
            }
            return newlist;
        }
      

  3.   

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
         dataBind();
    }protected void dataBind()
    {
              PagedDataSource pds = new PagedDataSource();
               //要分页的list列表
               List<Msg> list = MsgManager.getList();            AspNetPager1.RecordCount = list.Count;
                pds.DataSource = list;
                pds.AllowPaging = true;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.PageSize = AspNetPager1.PageSize;
                this.DataList1.DataSource = pds;
                this.DataList1.DataBind();
    }