使用AspNetPager分页

----------------------------------  HTML文件 ---------------------------------- 
 

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


<table align="center" cellpadding="5" width="95%" class="contentTable">
        <tr>
            <td>
                <webdiyer:AspNetPager ID="anpNewsList" runat="server" 
                        CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条" 
                        FirstPageText="首页" HorizontalAlign="Center" LastPageText="尾页" 
                        NextPageText="下一页" PageIndexBoxType="TextBox" PrevPageText="上一页" 
                        ShowPageIndexBox="Always" SubmitButtonText="" 
                        TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" 
                        CssClass="page_nav" CurrentPageButtonClass="pageCurrentPage" 
                        CustomInfoClass="pageInfo" LayoutType="Div" PageIndexBoxClass="txtPageNo" 
                        SubmitButtonClass="btnPageGo" PagingButtonsClass="" 
                    onpagechanged="anpNewsList_PageChanged" AlwaysShow="True">
                </webdiyer:AspNetPager>
            </td>
        </tr>
</table>

 

----------------------------------    *.cs 文件 ----------------------------------
    
/// <summary>
    ///绑定列表 
    /// </summary>
    public void BindData()
    {
        rptNewsList.DataSource = dtPager(NewsDAL.GetNewsList(Convert.ToInt32(ddlNewsTypeList.SelectedValue)).Tables[0]);
        rptNewsList.DataBind();
    }
    private PagedDataSource dtPager(DataTable dt)
    {
        anpNewsList.RecordCount = dt.Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = dt.DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = anpNewsList.CurrentPageIndex - 1;
        pds.PageSize = anpNewsList.PageSize;
        return pds;
    }
 
    protected void anpNewsList_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }

 

 
----------------------------------  CSS文件 ---------------------------------- 

/*分页*/
.pageInfo{ height:20px; line-height:20px; padding:5px 0; }
.page_nav{ height:20px; padding:5px 0; }
.page_nav a{ border:1px solid #CCC; height:15px; margin:5px 2px; padding:4px 5px; text-decoration:none; }
.page_nav a:hover{ background:#1a9bb8; color:#FFF; text-decoration:none; }
.page_nav .pageCurrentPage{ background:#066276;  height:15px; margin:5px 2px; padding:4px 5px; color:#FFF; text-decoration:none; }
.txtPageNo{ height:15px; text-align:center; width:20px; margin:0 2px; }
.btnPageGo{ background:url(../images/go.gif) no-repeat; width:29px; height:18px; border:0; } 

----------------------------------  images文件 ---------------------------------- 

posted @ 2014-08-18 10:14  linyongqin  阅读(98)  评论(0)    收藏  举报