AspNetPager sql 分页 Repeater(附分页控件DLL下载)

上次MYSQL的时候也将到了,利用AspNetPager 来进行分页,但是这次是用SQL来做,有时候 自己也会有点懵,不就是换下SQL连接的查询代码吗?


AspNetPager_sql_分页_Repeater(附分页控件DLL下载)






前台代码


     <asp:Repeater ID="Repeater1" runat="server" >  
        <ItemTemplate>

      <%#Eval("名称")%> 

      <%#Eval("点击量")%> 

     </ItemTemplate>   
    </asp:Repeater>


加上下面这段



<div class="list_pager">    
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="true"
     PageSize="20" CssClass="paginator"  CurrentPageButtonClass="cpb"
    LastPageText="尾页" FirstPageText="首页" PrevPageText="上一页" NextPageText="下一页"
     UrlPaging="false" NumericButtonTextFormatString="{0}"
     ShowCustomInfoSection="Left"  CustomInfoTextAlign="Left" LayoutType="Table" 
            
            CustomInfoHTML="页数 %CurrentPageIndex% of %PageCount%" ShowBoxThreshold="11" 
            UrlPageIndexName="页数" >
</webdiyer:AspNetPager>
    </div>



下面这里是淘宝风格 也加在下面即可


<style type="text/css">
/*拍拍网风格*/
.paginator { font: 18px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 16px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 16px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 16px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}

/*淘宝风格*/
.paginator { font: 18px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {border:solid 1px #ccc;color:#0063dc;cursor:pointer;text-decoration:none;}
.paginator a:visited {padding: 1px 16px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {border:1px solid #F50;font-weight:700;color:#F50;background-color:#ffeee5;}
.paginator a:hover {border:solid 1px #F50;color:#f60;text-decoration:none;}
.paginator a,.paginator a:visited,.paginator .cpb,.paginator a:hover  
{float:left;height:16px;line-height:16px;min-width:10px;_width:10px;margin-right:5px;text-align:center;
 white-space:nowrap;font-size:12px;font-family:Arial,SimSun;padding:0 3px;}
 </style>






后台绑定代码:


        string conn = "server=.;database=数据库;uid=sa;pwd=****"; ;

        SqlConnection con = new SqlConnection(conn);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from list order by Convert(int,点击量) desc", con);
        SqlDataReader dr = cmd.ExecuteReader();
        SqlDataAdapter adr = new SqlDataAdapter("select * from list order by Convert(int,点击量) desc ", conn);
        DataSet T = new DataSet();
        adr.Fill(T, "点击量");




        PagedDataSource pdsList = new PagedDataSource();
        pdsList.DataSource = T.Tables[0].DefaultView;
        pdsList.AllowPaging = true;//数据源允许分页
        pdsList.PageSize = this.AspNetPager1.PageSize;//取控件的分页大小
        pdsList.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;//显示当前页
        //设置控件
        this.AspNetPager1.RecordCount = T.Tables[0].Rows.Count;//记录总数
        this.AspNetPager1.PageSize = 50;
        this.Repeater1.DataSource = pdsList;
        this.Repeater1.DataBind();










webform
标签:AspNetPager sql 分页 Repeater