AspNetPager+Ajax实现无刷新分页

1.      首先应该添加引用到bin文件夹下:AspNetPager.dll

2.      在页面中添加:

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

3.      bin文件夹下的AspNetPager.dll添加到工具栏,拖拽至页面中:<webdiyer:AspNetPager ID="AspNetPager1" runat="server">    </webdiyer:AspNetPager>

4.      AspNetPager1添加属性:

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged" ShowCustomInfoSection="left" ShowInputBox="Auto" AlwaysShow="True" CustomInfoHTML="<font color='#333333'> %RecordCount% /每页%PageSize%行第%CurrentPageIndex%/%PageCount%页顺序 %StartRecordIndex%-%EndRecordIndex%</font> " NumericButtonCount="10" FirstPageText="首页" LastPageText="末页" NextPageText="下页"  PrevPageText="上页" CustomInfoSectionWidth="65%" CssClass="page_text" ShowBoxThreshold="2" InputBoxClass="pagetext" SubmitButtonClass="BtnStyle" SubmitButtonText="Go" PageSize="10">

    </webdiyer:AspNetPager>

标红的参数是要与后台交互的数据。

5.      在后台的定义变量

private int pagesize = 10;//每页的行数

        private int totalpagesize = 0;//总的页数

        private int pageindex = 1;//页码

6.      使用方法读取数据填充到Gridview中。

7.      using (SqlConnection con = new SqlConnection(strcon))

                {

                    using (SqlCommand cmd = con.CreateCommand())

                    {

                        con.Open();

                        cmd.CommandText = "select * from articleinfo";

                        totalpagesize = Convert.ToInt32(cmd.ExecuteScalar());//获取总的数据行数

                        this.AspNetPager1.RecordCount = totalpagesize;

                        cmd.CommandText = "ProcarticleInfo";

                        //表明调用的是存储过程

                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@PAGESIZE", pagesize);

                        cmd.Parameters.AddWithValue("@PAGEINDEX", pageindex);

                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);

                        DataTable dt = new DataTable();

                        adapter.Fill(dt);

                        this.GridView1.DataSource = dt;

                        this.GridView1.DataBind();

                    }

                } 

8.调用page_changed的方法使更换页码

protected void AspNetPager1_PageChanged(object sender, EventArgs e)

        {

          

            this.AspNetPager1.PageSize = pagesize;

            pageindex= this.AspNetPager1.CurrentPageIndex;

            DataBindArticle();

        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值