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;
        }

上一篇:阿里云发布 Spring Boot 新脚手架,真香


下一篇:LeetCode 209:最小长度的子数组 Minimum Size Subarray Sum