DataList分页方法及分页控件的使用

来源:互联网 发布:js给数组增加元素 编辑:程序博客网 时间:2024/05/16 03:40
 1、此方法为直接在每次绑定数据时分页

 private void BindZCFG()
    {
        CMS.BLL.zx_xxManage zxxx = new CMS.BLL.zx_xxManage();
        string sql = "select * from zx_xx where wj in (select  wj from zx_zcfg where lb in(select bm from bmqk where bmlb='zxlb' and bm ='4D00' and bbrq>'2008-2-17') and y='1') order by bbrq desc,bt";

        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = CMS.CommonUtility.BXDBUtility.DataReaderToDataTable(zxxx.GetExeCmdResult(sql)).DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = this.AspNetPager1.PageSize;
        this.AspNetPager1.RecordCount = ps.DataSourceCount;
        ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;

        this.LBCount.Text = ps.DataSourceCount.ToString();
        this.LBPagecount.Text = ps.PageCount.ToString();
        this.LBpagesize.Text = this.AspNetPager1.PageSize.ToString();
        this.DLCJTT.DataSource = ps;
        this.DLCJTT.DataBind();
        zxxx.Dispose();
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        this.BindZCFG();
    }

2、此方法为只在第一次获取记录数,在每次分页时只是绑定要显示的记录。

if (!IsPostBack)
        {
            this.paging();
            this.BindDLjob();
        }
    }
    private void BindDLjob()
    {
        CMS.BLL.JopManage jm = new CMS.BLL.JopManage();
        System.Collections.ArrayList al = jm.Get("str",this.AspNetPager1.CurrentPageIndex-1,this.AspNetPager1.PageSize);
        this.DLjob.DataSource = al;
        this.DLjob.DataBind();
        jm.Dispose();
        al.Clear();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.BindDLjob();
    }
    //分页
    private void paging()
    {
        CMS.BLL.JopManage jm = new CMS.BLL.JopManage();
        System.Collections.ArrayList al = jm.Get("str")
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = al;
        ps.AllowPaging = true;
        ps.PageSize = this.AspNetPager1.PageSize;
        this.AspNetPager1.RecordCount = ps.DataSourceCount;
        ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
    }

3、分页控件样式

共 <asp:Label ID="LBCount" runat="server" Text="Label"></asp:Label> 条信息  <asp:Label ID="LBpagesize"
               runat="server" Text="Label"></asp:Label> 条/页   共 <asp:Label ID="LBPagecount" runat="server"
                   Text="Label"></asp:Label> 页 

 <webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="20" FirstPageText="第一页" ForeColor="#404040" LastPageText="最后一页" NextPageText="下一页" NumericButtonCount="20" PageIndexBoxType="TextBox" Font-Size="12px" PrevPageText="上一页" ReverseUrlPageIndex="True" ShowFirstLast="False" OnPageChanging="AspNetPager1_PageChanging"></webdiyer:AspNetPager>

原创粉丝点击