asp.net中使用分页控件,并绑定数据到GridView或Repeater

        /// <summary>
        /// (asp.net网页中)使用显示上下页的控件(LtpPageControl.Page02)--GridView
        /// </summary>
        /// <param name="pagectrl">LtpPageControl.Page02 控件</param>
        /// <param name="gv">GridView控件</param>
        /// <param name="ds">运行SpPageOrder得到的DataSet</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="PageSize">页面数据条数</param>
        /// <returns></returns>
        public static bool LtpPage(LtpPageControl.Page02 pagectrl, GridView gv, DataSet ds, int pageIndex, int PageSize)
        {
            try
            {
                gv.DataSource = ds.Tables[0].DefaultView;
                int record_Count = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());

                int totalPages = int.Parse(Math.Ceiling((double)record_Count / PageSize).ToString());
                if (totalPages > 0)
                {
                    if (pageIndex > totalPages) pageIndex = totalPages - 1;
                }
                else
                {
                    pageIndex = 1;
                }
                gv.DataBind();

                pagectrl.Page_Count = totalPages;
                pagectrl.Page_Size = PageSize;
                pagectrl.Page_Current = pageIndex;
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        #endregion

        #region (asp.net网页中)使用显示上下页的控件(LtpPage)--Repeater
        /// <summary>
        /// (asp.net网页中)使用显示上下页的控件(LtpPageControl.Page02)--Repeater
        /// </summary>
        /// <param name="pagectrl">LtpPageControl.Page02 控件</param>
        /// <param name="rp">Repeater控件</param>
        /// <param name="ds">运行SpPageOrder得到的DataSet</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="PageSize">页面数据条数</param>
        /// <returns></returns>
        public static bool LtpPage(LtpPageControl.Page02 pagectrl, Repeater rp, DataSet ds, int pageIndex, int PageSize)
        {
            try
            {
                rp.DataSource = ds.Tables[0].DefaultView;
                int record_Count = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());

                int totalPages = int.Parse(Math.Ceiling((double)record_Count / PageSize).ToString());
                if (totalPages > 0)
                {
                    if ((pageIndex + 1) > totalPages)
                        pageIndex = totalPages - 1;
                }
                else
                {
                    pageIndex = 0;
                }
                rp.DataBind();

                pagectrl.Page_Count = totalPages;
                pagectrl.Page_Size = PageSize;
                pagectrl.Page_Current = pageIndex;
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

转载于:https://www.cnblogs.com/pukuimin/archive/2012/08/08/2988137.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值