前台代码:
代码
复制代码 代码如下:
<div id="newslistdiv">
<asp:DataList ID="NewsList" runat="server" Width="820px">
<HeaderTemplate>
<div>
<img src="/UploadFiles/2021-04-02/newslisthead.gif"></HeaderTemplate>
<ItemTemplate>
<dl>
<dd>
·<a href="#" class="rlk" onclick='window.location.href="DetailNews.aspx?ID=<%#Eval("NewsID") %>"'><%#Eval("NewsTitle") %></a>
&nbsp;&nbsp;&nbsp;<%#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();
}
标签:
aspnetpager,DataList,分页

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“asp.net 通过aspnetpager为DataList分页”

暂无“asp.net 通过aspnetpager为DataList分页”评论...