51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> asp.net >> 文章正文

ASP.NET分页及光棒效果

更新时间:2012-1-7:  来源:51代码网

public int Pages
        {
            get { return int.Parse(ViewState["page"].ToString()); }
            set { ViewState["page"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Pages = 1;
                //string no = Request.QueryString["page"];
                //Pages = no == null ? 1 : int.Parse(no);
                PageShow();
                URLPaged();
            }
           // BindRepeater();
        }        #region 光棒效果
        protected void rptBook_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HtmlTableRow tr = e.Item.FindControl("tr") as HtmlTableRow;
                tr.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='red'");
                tr.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
            }
        }
        #endregion
        #region post分页
        public void PageShow()
        {
            PagedDataSource pds = new PagedDataSource();
             //为pagedDataSource设置数据源
             BookInfoBll bookbll = new BookInfoBll();
           
             pds.DataSource = bookbll.GetAll();
             //设置Repeater的数据源为PagedDataSource
             this.rptBook.DataSource = pds;
             //允许分页
             pds.AllowPaging = true;
             //设置分页的条数
             pds.PageSize = 4;
             ViewState["count"] = pds.PageCount;
             pds.CurrentPageIndex = Pages - 1;
           
            //得到当前页和总也数
             this.lnkup.Enabled = true;
             this.lnkDwon.Enabled = true;
             if (pds.IsFirstPage)
             {
                 lnkup.Enabled = false;
             }
             if (pds.IsLastPage)
             {
                 lnkDwon.Enabled = false;
             }
             this.rptBook.DataBind();
        }
      

        //首页
        protected void lnkStart_Click(object sender, EventArgs e)
        {
            Pages = 1;
            PageShow();
        }
        //下一页
        protected void lnkup_Click(object sender, EventArgs e)
        {
            Pages--;
            PageShow();
        }
        //上一页
        protected void lnkDwon_Click(object sender, EventArgs e)
        {
            Pages++;
            PageShow();
        }
        //尾页
        protected void lnkLast_Click(object sender, EventArgs e)
        {
            Pages = int.Parse(ViewState["count"].ToString());
            PageShow();
        }
        #endregion

        #region Url分页
        public void URLPaged()
        {
            PagedDataSource pds = new PagedDataSource();
            BookInfoBll bookbll = new BookInfoBll();
          pds.AllowPaging = true;
            pds.PageSize = 4;
            List<BookInfo> lst = bookbll.GetAll();
            //List<BookInfo> list = lst.Skip((pds.PageSize) * (Pages - 1)).Take(pds.PageSize).ToList();
            pds.DataSource = lst;
            ViewState["count"] = pds.PageCount;
            //pds.VirtualCount = lst.Count;
            //pds.CurrentPageIndex = Pages - 1;
            //Response.Write(Pages);
            if (Request.QueryString["page"] != null)
            {
                Pages = int.Parse(Request.QueryString["page"].ToString());
            }
            pds.CurrentPageIndex = Pages - 1;
            //int pageTotal = (pds.VirtualCount + (pds.PageSize - 1)) / pds.PageSize;
            //hykLast.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + pageTotal;
            //hykStart.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
            //hykUp.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pages - 1);
            //hykDwon.NavigateUrl = Request.CurrentExecutionFilePath + "?page="+(Pages+1);
            //if (Pages == 1)
            //{
            //    hykUp.NavigateUrl = "";
            //}
            //if (Pages == pageTotal)
            //{
            //    hykDwon.NavigateUrl = "";
            //}
            if (!pds.IsFirstPage)
            {
                hykUp.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pages - 1);
               hykStart.NavigateUrl=Request.CurrentExecutionFilePath;
            }
            if (!pds.IsLastPage)
            {
                hykDwon.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pages + 1);
                hykLast.NavigateUrl =Request.CurrentExecutionFilePath+ "?page="+ ViewState["count"];
               
            }
            this.rptBook.DataSource = pds;
            this.DataBind();
        }
        #endregion

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |