|
代码
复制代码 代码如下:
<div id="newslistdiv">
<ASP:DataList ID="NewsList" runat="server" Width="820px">
<HeaderTemplate>
<div>
<img src="../loginimages/newslisthead.gif" alt="" /></div>
</HeaderTemplate>
<ItemTemplate>
<dl>
<dd>
・<a href="#" class="rlk" onclick='window.location.href="DetailNews.ASPx?ID=<%#Eval("NewsID") %>"'><%#Eval("NewsTitle") %></a>
<%#Eval("NewsTime", "{0:yyyy-MM-dd}")%><br />
</dd>
</dl>
</ItemTemplate>
</ASP:DataList>
</div>
<div style="margin-bottom: 2px;" align="center">
<webdiyer:ASPNETPager ID="ASPNETPager1" runat="server" PageSize="15" FirstPageText=" 首页 "
LastPageText=" 尾页 " NextPageText=" " OnPageChanged="ASPNETPager1_PageChanged"
PrevPageText=" " Width="100%" AlwaysShow="true" CssClass="anpager">
</webdiyer:ASPNETPager>
</div>
后台代码:
代码
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindNewsDatalist();
}
}
//绑定DataList的数据源
private void BindNewsDatalist()
{
FJDWS.BusinessLogic.LNewsManager lnewsmanager = new FJDWS.BusinessLogic.LNewsManager();
this.ASPNETPager1.RecordCount = lnewsmanager.FindAll().Count;
PagedDataSource pds = new PagedDataSource(); //定义一个PagedDataSource类来执行分页功能
pds.DataSource = lnewsmanager.FindAll();
pds.AllowPaging = true;
pds.CurrentPageIndex = ASPNETPager1.CurrentPageIndex - 1;
pds.PageSize = ASPNETPager1.PageSize;
this.NewsList.DataSource = pds;
NewsList.DataBind();
}
protected void ASPNETPager1_PageChanged(object src, EventArgs e)
{
//ASPNETPager1.CurrentPageIndex = e.NewPageIndex;
BindNewsDatalist();
}
AspNet技术:asp.net 通过aspnetpager为DataList分页,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。