asp.net自定义分页控件示例


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IOCS.WEB.UserControl
{
    public partial class Pagination : System.Web.UI.UserControl
    {
        public event EventHandler PageButtonClick;
        public bool FirstPost = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              

}
            // 只輸入數字
            txtpage.Attributes.Add("onclick",
                @"if(!((event.keyCode>=48&&event.keyCode<=57)
                    ||(event.keyCode>=96&&event.keyCode<=105)
                    ||(event.keyCode==8)))event.returnValue=false;"
              );

}
        GridView _gv;

/// <summary>
        /// 需要分頁的GridView
        /// </summary>
        public GridView TargetControlID
        {
            set
            {
                _gv = value;
            }
            get
            {
                return _gv;
            }
        }

protected void PagerButtonClick(object sender, EventArgs e)
        {
            //獲得linkebutton的參數值
            string arg = ((LinkButton)sender).CommandArgument;
            switch (arg)
            {
                case ("next"):
                    {
                        if (_gv.PageIndex < _gv.PageCount - 1)
                        {
                            _gv.PageIndex=_gv.PageIndex+1;
                        }
                        break;
                    }
                case ("prev"):
                    {
                        if (_gv.PageIndex > 0)
                        {
                            _gv.PageIndex--;
                        }
                        break;
                    }
                case ("first"):
                    {
                        _gv.PageIndex = 0;
                        break;
                    }
                case ("last"):
                    {
                        if (_gv.PageCount > 0)
                        {
                            _gv.PageIndex = _gv.PageCount - 1;
                        }
                        break;
                    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzsjd.html