asp.net 通过aspnetpager为DataList分页
程序员文章站
2024-03-08 15:06:34
前台代码: 代码 复制代码 代码如下:
前台代码:
代码
<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();
}
代码
复制代码 代码如下:
<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();
}
推荐阅读
-
asp.net 通过aspnetpager为DataList分页
-
asp.net中Datalist使用数字分页的实现方法
-
Asp.Net分页和AspNetPager控件的使用
-
asp.net下Repeater使用 AspNetPager分页控件
-
asp.net分页控件AspNetPager的样式美化
-
Asp.Net数据控件引用AspNetPager.dll分页实现代码
-
asp.net中Datalist使用数字分页的实现方法
-
Asp.Net分页和AspNetPager控件的使用
-
asp.net分页控件AspNetPager的样式美化
-
Asp.Net数据控件引用AspNetPager.dll分页实现代码