如何为每5页切片分页

时间:2010-07-29 06:34:33

标签: asp.net

我只是想每隔5页切片一次,因为页面太多,这就是为什么底部的分页看起来太拥挤了。

        int kategoriId = Convert.ToInt32(Request.QueryString["ID"]);

        using (HEDataContext db = new HEDataContext())
        {

            var productList = (from p in db.KATEGORI_03s
                              where p.kategori_02_id == kategoriId
                              select new 
                              {
                                ID= p.ID,
                                Name = p.Name,                                    
                                Bilgi = p.Bilgi,
                                Img1 = p.Img1,
                                Img2 = p.Img2,
                                Count = db.KATEGORI_03s.Count()
                              }).Skip(pg * 9).Take(take);


            PagedDataSource page = new PagedDataSource();
            page.AllowCustomPaging = true;
            page.AllowPaging = true;
            page.DataSource = productList;
            page.PageSize = 9;

            DLProductsList.DataSource = productList;
            DLProductsList.DataBind();

            if (!IsPostBack)
            {
                CreatePagingControl();
            }

        }




    public void CreatePagingControl()
    {

        int totalPageCount = (CountTable() / 9) + 1;
        int ID = Convert.ToInt32(Request.QueryString["ID"]);
        int pg = Convert.ToInt32(Request.QueryString["pg"]);
        int kategori_01_id = Convert.ToInt32(Request.QueryString["kategori_01_id"]);

        string lnk = "";

        for (int i = 0; i < (CountTable() / 9) + 1; i++){


            if (pg == 0)
            {
                firstpage.Visible = false;
                previous.Visible = false;
            }


            if (pg == (totalPageCount - 1))
            {
                next.Visible = false;
                lastpage.Visible = false;
            }


            firstpage.NavigateUrl = "Products-List.aspx?kategori_01_id=" + kategori_01_id + "&ID=" + ID + "&pg=0";
            previous.NavigateUrl = "Products-List.aspx?kategori_01_id=" + kategori_01_id + "&ID=" + ID + "&pg=" + (pg - 1).ToString();
            next.NavigateUrl = "Products-List.aspx?kategori_01_id=" + kategori_01_id + "&ID=" + ID + "&pg=" + (pg + 1).ToString();
            lastpage.NavigateUrl = "Products-List.aspx?kategori_01_id=" + kategori_01_id + "&ID=" + ID + "&pg=" + (totalPageCount - 1).ToString();


            if (i == pg)  
                lnk += "<span>" + (i + 1).ToString() + "</span>";
            else
                lnk += "<a href='Products-List.aspx?kategori_01_id=" + kategori_01_id + "&ID=" + ID + "&pg=" + i.ToString() + "'>" + (i + 1).ToString() + "</a>";


            lnk += "&nbsp;<img src='images/paging-pipe.gif' class='pagingpipe' alt='' />&nbsp;";

        }

        lblPageName.Text = lnk;

    }

1 个答案:

答案 0 :(得分:1)

这是一个非常常见的问题,你可以使用像here下面这样的jQuery小部件来做到这一点

您只需提供后端实现即可获取所需的数据。