zoukankan      html  css  js  c++  java
  • 用aspnetpager实现datalist分页

    微软的Datalist在做电子相册时候必不可少,但是不支持分页功能,都出到2008了还是没有分页功能,幸好网上有个专业的分页控件aspnetpager,帮我们解决了大问题,说实在话的,网上关于datalist分页的办法很多,但是我觉得都不是很简单实用,有的是url提交,有的是存储过程分页,一个字不方便。下面就是aspnetpager分页,代码。

    1.首先下载aspnetpager控件,http://www.webdiyer.com/download/default.aspx

    2.在工具箱里面添加aspnetpager控件。

    3.前台引用

    <asp:DataList runat="server" Width="100%" Border="0" CellSpacing="0" CellPadding="0" RepeatColumns="4" RepeatDirection="Horizontal">
        <ItemTemplate>
           <a href='<%# "PicView.aspx?PicID="+Eval("PicID")%>'><asp:Image ID="imPic" runat="server" ImageUrl='<%# Bind("PicUrl")%>' width="104" height="76" BorderWidth="1" /><br />
                              <asp:Label runat="server" ID="lblTitle" Text='<%# Bind("DisTitle")%>'></asp:Label></a>
        </ItemTemplate>
        <ItemStyle CssClass="word_green" HorizontalAlign="Center" />
        </asp:DataList>
       
    <webdiyer:AspNetPager runat="server"   PageSize="5" ShowBoxThreshold="1" AlwaysShow="True" FirstPageText="首页" LastPageText="末页"
    NextPageText="下一页" PrevPageText="上一页" onpagechanging="AspNetPager1_PageChanging">
    </webdiyer:AspNetPager>
        4.后台代码

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindData();
                }
            }

            private void BindData()
            {
            
                conn = ConfigurationManager.ConnectionStrings["STRING_SqlConn"].ToString();
                object[] para = { 0, picid };
                DataTable dt = DataOperator.TableUseTrans(conn, "SP_Pic_GetView", para);
                DataView dv = dt.DefaultView;
                //对用于分页的类的引用
                PagedDataSource pds = new PagedDataSource();
                pds.DataSource = dv;//设置数据源(DataTable类型)
                pds.AllowPaging = true;
                //每页显示的行数
                //pds.PageSize = 12;
               
             
                AspNetPager1.RecordCount = dv.Count;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.PageSize = AspNetPager1.PageSize;
                DataList.DataSource= pds;
                DataList.DataBind();
               

            }

            PageChanged事件:
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
         {
             DataList1_Bind();
         }
    在使用AspNetPager时别忘了添加onpagechanged="AspNetPager1_PageChanged"事件.

  • 相关阅读:
    25 自动类型转换
    24 枚举Enum类
    23 Collection集合常用方法讲解
    Eclipse 快捷键
    21 泛型
    20 IO流(十七)——Commons工具包,FileUtils(二)——copy方法
    19 IO流(十六)——Commons工具包,FileUtils(一)
    18 IO流(十五)——RandomAccessFile随机访问文件及使用它进行大文件切割的方法
    CentOS6.5-6.9安装 docker
    linux开启端口
  • 原文地址:https://www.cnblogs.com/jinqi79731/p/1880095.html
Copyright © 2011-2022 走看看