您现在的位置: 365建站网 > 365文章 > 利用分页控件AspNetPager来做数据的分页

利用分页控件AspNetPager来做数据的分页

文章来源:365jz.com     点击数:224    更新时间:2011-05-14 14:36   参与评论

AspNetPager是第三方控件,下载地址:http://www.webdiyer.com/AspNetPagerDocs/index.html

然后通过Visaul Studio 2005的“选择项”把下载后的控件DLL加载到我们的控件工具箱中。

           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />
                    <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
                    <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                    <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
                    <asp:BoundField DataField="Address" HeaderText="Address" />
                    <asp:BoundField DataField="City" HeaderText="City" />
                </Columns>
            </asp:GridView>
            <webdiyer:AspNetPager ID="AspNetPager1" PageIndexBoxType="DropDownList" CustomInfoTextAlign="Left" FirstPageText="首页"
                PrevPageText="上一页" TextAfterPageIndexBox="页" TextBeforePageIndexBox ="转到" SubmitButtonText="Go"  ShowPageIndexBox ="Always" LastPageText="尾页" NextPageText="下一页" ShowCustomInfoSection="Left" CustomInfoHTML="当前%CurrentPageIndex%页,共有%PageCount%页"
                runat="server" OnPageChanging="AspNetPager1_PageChanging">
            </webdiyer:AspNetPager>
        </div>

///

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    public void bind()
    {
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Northwind.mdb");
        OleDbCommand cmd = new OleDbCommand("select * from Customers", con);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource ps = new PagedDataSource();
        ps.AllowPaging = true;
        ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
        ps.DataSource = ds.Tables[0].DefaultView;
        this.GridView1.DataSource = ps;
        this.GridView1.DataBind();

    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        bind();
    }

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (224人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号