C# 分页控件

这篇博客介绍了如何在C#中使用分页控件,提供了具体的代码示例和数据传递方法。通过调用`setPage`函数,将DataSet对象传入分页控件进行数据绑定和显示。
摘要由CSDN通过智能技术生成

界面:


代码:

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Data.SqlClient;


namespace wyyNavigator
{
    public partial class wyyNavigator : UserControl
    {
        #region 变量定义
        private int totalCount = 0;//总数据个数
        private int pageCount = 0;//总页数
        private int currentPageIndex = 1;//当前页索引
        private int pageSize = 10;//每页分页大小
        private int remainder = 0;//最后一页剩余个数
        private bool isAutoUpdateLabelTip = true;//获取或设置是否自动更新分页标签内容提示,默认为true
        private string sqlAddress = "";//"Data Source=192.168.100.144;Initial Catalog=test;User ID=sa;Password=123456;";//DataGridViewd要绑定的表名                                     
        private string tableName = "";//"DataSource";//DataGridViewd要绑定的表名
        private string strWhere = "";
        private DataSet dsAll = null;//总数据源
        #endregion
        #region 传入参数
        #region 通过数据[库]查询
        /// <summary>
        /// 链接数据库地址
        /// </summary>
        public string SqlAddress
        {
            get { return this.sqlAddress; }
            set { this.sqlAddress = value; base.Refresh(); }
        }
        /// <summary>
        /// 查询表
        /// </summary>
        public string TableName
        {
            get { return this.tableName; }
            set { this.tableName = value; base.Refresh(); }
        }
        /// <summary>
        /// 添加自定义条件
        /// </summary>
        public string StrWhere
        {
            get { return this.strWhere; }
            set { this.strWhere = value; base.Refresh(); }
        }
        #endregion
        #region 通过数据[源]查询
        /// <summary>
        /// 传递dataset数据源
        /// </summary>
        public DataSet DsAll
        {
            get { return this.dsAll; }
            set { this.dsAll = value; base.Refresh(); }
        }
        #endregion
        #region 外调函数
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void dataBand()
        {
            comboBoxNum();
            showDataGirdView();
        }
        /// <summary>
        /// 返回当前页面数据
        /// </summary>
        /// <returns></returns>
        public DataGridView outputDGV()
        {
            return dataGridView_show;
        }
        #endregion
        #endregion
        #region 加载
        //定义委托
        public delegate void BindHandle(object sender, EventArgs e);
        /// <summary>
        /// 绑定数据源事件
        /// </summary>
        //public event BindHandle BindSource;
        public wyyNavigator()
        {
            InitializeComponent();
        }
        #endregion
        //加载事件
        private void wyyNavigator_Load(object sender, EventArgs e)
        {
            comboBoxNum();
            showDataGirdView();
        }
        #region 分页操作
        //首页
        private void label_first_Click(object sender, EventArgs e)
        {
            currentPageIndex = 1;
            showDataGirdView();
        }
        //末页
        private void label_end_Click(object sender, EventArgs e)
        {
            currentPageIndex = pageCount;
            showDataGirdView();
        }
        //上一页
        private void label_up_Click(object sender, EventArgs e)
        {
            if (currentPageIndex <= pageCount && currentPageIndex != 1)
            {
                currentPageIndex--;
                showDataGirdView();
            }


            if (isAutoUpdateLabelTip)
            {
                updateSplitPageLabelTip();
            }
        }
        //下一页
        private void label_down_Click(object sender, EventArgs e)
        {
            if (currentPageIndex < pageCount && currentPageIndex != pageCount)
            {
                currentPageIndex++;
                showDataGirdView();
            }
            if (isAutoUpdateLabelTip)
            {
                updateSplitPageLabelTip();
            }
        }
        //第几页
        private voi
一、AspNetPager支持两种方式分页: 一种是PostBack方式分页, 一种是通过Url来实现分页以及Url重写功能 二、AspNetPager支持各种数据绑定控件GridView、DataGrid、DataList、Repeater以及自定义的数据绑定控件分页功能十分强大。 三、AspNetPager分页控件本身并不显示任何数据,而只显示分页导航元素,数据在页面上的显示方式与该控件无关,所以需要手写数据连接方法来配合, 四、结合TOP 。。。NOT IN 的通用存储过程分页方法使用AspNetPager十分实用 测试控件datalist aspnetpager 的分页方法示例 分页方法为 PostBack 方式 1、 首先将AspNetPager.dll复制于应用程序下的bin目录,打开解决方案,引入dll文件 2、 在工具栏中添加控件,这样可以支持拖拽使用 3、 要使用AspNetPager 要为其设置最基本的属性 使用 SqlServer Northwind数据库的 Products表 protected Wuqi.Webdiyer.AspNetPager AspNetPager1; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DataList DataList1; private void Page_Load(object sender, System.EventArgs e) { this.AspNetPager1.PageSize=10; //设置每也显示的记录条数 if(!IsPostBack) //只在页面第一次加载时起作用 { SqlDBManager db = new SqlDBManager(System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionString"]); AspNetPager1.RecordCount=db.CountPage("products");//获得要使用表的记录总数 //db.CountItems自定义的方法 this.BindData(); } } private void BindData() { SqlDBManager db= new SqlDBManager(System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionString"].ToString(); DataList1.DataSource=db.FenPage(this.AspNetPager1.PageSize,this.AspNetPager1.CurrentPageIndex,"productid","products","productid,productname,unitprice,unitsinstock",""); //自定义方法由 TOP not in 存储过程分页方法改编 this.DataList1.DataBind(); //控件数据绑定 this.Label1.Text="当前第"+this.AspNetPager1.CurrentPageIndex+"页 总"+this.AspNetPager1.PageCount+"页"; } private void AspNetPager1_PageChanged(object sender, System.EventArgs e) { //页索引改变方法 this.BindData(); } 设计页效果 <asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 296px; POSITION: absolute; TOP: 96px" runat="server"> <HeaderTemplate> <table border='1'> <tr> <td>产品ID</td> <td>产品名称</td> <td>产品数量</td> <td>产品单价</td> </tr> </HeaderTemplate> <FooterTemplate> </table> </FooterTemplate> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem,"Productid")%></td> <td><%# DataBinder.Eval(Container.DataItem,"productname")%></td> <td><%# DataBinder.Eval(Container.DataItem,"unitprice")%></td> <td><%# DataBinder.Eval(Container.DataItem,"unitsinstock")%></td> </tr> </ItemTemplate> </asp:DataList> <webdiyer:AspNetPager id="AspNetPager1" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 40px" runat="server" Width="500px" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" Height="40px" NumericButt PagingButt ShowNavigati ShowInputBox="Always" TextAfterInputBox="页" TextBeforeInputBox="跳转到第" AlwaysShow="True"> </webdiyer:AspNetPager> <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 120px; POSITION: absolute; TOP: 56px" runat="server">Label</asp:Label>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值