今天整了半天才把DataList的分页搞定下面把我的设计过程给大家讲讲
前台代码
<div id=newslistdiv>
<asp:DataList ID=NewsList runat=server Width=px>
<HeaderTemplate>
<div>
<img src=/loginimages/newslistheadgif alt= /></div>
</HeaderTemplate>
<ItemTemplate>
<dl>
<dd>
·<a # class=rlk onclick=windowlocationDetailNewsaspx?ID=<%#Eval(NewsID) %>><%#Eval(NewsTitle) %></a>
<%#Eval(NewsTime {:yyyyMMdd})%><br />
</dd>
</dl>
</ItemTemplate>
</asp:DataList>
</div>
<div align=center>
<webdiyer:AspNetPager ID=AspNetPager runat=server PageSize= FirstPageText= 首页
LastPageText= 尾页 NextPageText= 下一页 OnPageChanged=AspNetPager_PageChanged
PrevPageText= 上一页 Width=% AlwaysShow=true CssClass=anpager>
</webdiyer:AspNetPager>
</div>
后台代码
protected void Page_Load(object sender EventArgs e)
{
if (!IsPostBack)
{
BindNewsDatalist();
}
}
//绑定DataList的数据源
private void BindNewsDatalist()
{
FJDWSBusinessLogicLNewsManager lnewsmanager = new FJDWSBusinessLogicLNewsManager();
thisAspNetPagerRecordCount = lnewsmanagerFindAll()Count;
PagedDataSource pds = new PagedDataSource(); //定义一个PagedDataSource类来执行分页功能
pdsDataSource = lnewsmanagerFindAll();
pdsAllowPaging = true;
pdsCurrentPageIndex = AspNetPagerCurrentPageIndex ;
pdsPageSize = AspNetPagerPageSize;
thisNewsListDataSource = pds;
NewsListDataBind();
}
protected void AspNetPager_PageChanged(object src EventArgs e)
{
//AspNetPagerCurrentPageIndex = eNewPageIndex;
BindNewsDatalist();
}