Exemplo n.º 1
0
        public void GetPageFromDB(int pageNum)
        {
            string connectionString = Global.WaifString;

            _connection = new SqlConnection(connectionString);
            _connection.Open();

            object Count = new SqlCommand("SELECT COUNT(*) FROM Waifu", _connection).ExecuteScalar();

            PageCount      = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Count) / Convert.ToDouble(ItemsOnPage)));
            MainPagination = new Pagination(PageCount, pageNum);

            SqlCommand GetPageCommand = new SqlCommand("EXEC GetWaifuPage @offset, @page_size", _connection);

            GetPageCommand.Parameters.AddWithValue("offset", ItemsOnPage * (PageNumber - 1));
            GetPageCommand.Parameters.AddWithValue("page_size", ItemsOnPage);

            SqlDataReader rd = GetPageCommand.ExecuteReader();

            while (rd.Read())
            {
                WaifuLight item = new WaifuLight(rd);
                PageContent.Add(item);
            }
            rd.Close();

            ContentRepeater.DataSource = PageContent;
            ContentRepeater.DataBind();
            PaginationRepeater.DataSource = MainPagination.PaginationElements;
            PaginationRepeater.DataBind();
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.TotalPages = (int)Math.Ceiling((double)this.TotalItems / this.ItemCountPerPage);
            this.Pages      = new List <PaginationPage>();
            this.ItemsRight = 3;
            this.ItemsLeft  = 3;

            bool showFirstLink = this.TotalPages > 0 ? true : false;
            bool showLastLink  = this.TotalPages > 0 ? true : false;

            if (this.CurrentPage > this.TotalPages)
            {
                showFirstLink = false;
                showLastLink  = false;
            }

            this.AppendExistedQuery();

            if (this.CurrentPage == 0)
            {
                this.CurrentPage = 1;
            }

            if ((int)this.CurrentPage <= this.ItemsLeft)
            {
                this.ItemsRight += this.ItemsLeft - (int)this.CurrentPage;
            }

            for (int i = 1; i <= this.TotalPages; i++)
            {
                PaginationPage p = new PaginationPage()
                {
                    Value = i, CssClass = "", Url = Request.Url.AbsolutePath + "?" + this.ExistedQuery + "&" + this.QueryKey + "=" + i
                };
                if (this.CurrentPage == p.Value)
                {
                    p.CssClass += this.ActiveCssClass + " ";
                }

                if (p.Value == (int)this.CurrentPage || (p.Value <= ((int)this.CurrentPage + this.ItemsRight) && p.Value > this.CurrentPage) || (p.Value >= ((int)this.CurrentPage - this.ItemsLeft) && p.Value < this.CurrentPage))
                {
                    this.Pages.Add(p);

                    if (p.Value == 1)
                    {
                        showFirstLink = false;
                    }

                    if (p.Value == this.TotalPages)
                    {
                        showLastLink = false;
                    }
                }
            }

            if (showFirstLink == true)
            {
                this.FirstPageUrl = this.GeneratePageUrl("1");
            }

            if (showLastLink == true)
            {
                this.LastPageUrl = this.GeneratePageUrl(this.TotalPages.ToString());
            }

            PaginationRepeater.DataSource = this.Pages;
            PaginationRepeater.DataBind();
        }