asp

位置:IT落伍者 >> asp >> 浏览文章

通过aspnetpager为DataList分页


发布日期:2022年08月04日
 
通过aspnetpager为DataList分页

今天整了半天才把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>

&nbsp;&nbsp;&nbsp;<%#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();

}

上一篇:如何用ASP编写网站统计系统

下一篇:能够生成googlexml地图的asp源码