打印本文 打印本文 关闭窗口 关闭窗口
ASP.NET分页组件学与用——教学篇
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2926  更新时间:2009/4/23 10:41:51  文章录入:mintao  责任编辑:mintao
 

        [DefaultValue(1),Category("Customer")]

        public int AllCount

        {

            get

            {

                return _allCount;

            }

            set

            {

                if(_allCount < 0)

                    throw new Exception("记录总条数不能为负数");

                else

                    _allCount = value;

            }

        }

 

        [DefaultValue(1),Category("Customer")]

        public int Pages//总页数

        {

            get

            {

                if(this._allCount % this._count > 0)

                    return ((int)this._allCount / this._count) + 1;

                else

                    return ((int)this._allCount / this._count);

            }

        }

 

        [DefaultValue(1),Category("Customer")]

        public int ShowPages

        {

            set

            {

                if(value > 0)

                    _showPages = value;

                else

                    _showPages = 9;

            }

            get

            {

                return _showPages;

            }

    }

 

在定义的属性中,有一个叫Pages的属性,该属性不需要从外面传值,而过计算出来的。他的值等于总记录条数除以每页显示的记录条数(具体请见代码)。

 

现在我们要把这些值显示出来,用下面的代码显示:

//分页条分三部分,leftInfo是最左边的部分,用来显示当前页/总页数,每页显示的记录条数

leftInfo = "页:" + this.CurrentPage.ToString() + "/" + this.Pages.ToString() + "&nbsp;&nbsp;" + "每页" + this.Count.ToString() + "条" + "&nbsp;&nbsp;共" + this.AllCount.ToString() + "条";     

 

第二段比较复杂。组件的页面导航数字是连续的,所以,我定义了一个最小值和最大值:

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口