asp.net下用AspNetPager分页控件对DataList进行分页
先来看x文件代码
<p class="orderslist">
<!--增加datalist-->
<table id="customers" width="100%" cellpadding="0" cellspacing="0" border="1px">
<tbody>
<tr align="center" valign="middle" height="30px">
<th width="30%">订单编号</th>
<th width="50%">订餐时间</th>
<th width="20%">操作</th>
</tr>
<asp:datalist id = "orders_list" runat = "server" repeatlayout = "flow" repeatdirection="horizontal">
<itemtemplate>
<tr height="30px" align="center" valign="middle">
<td><%# eval("ord_no")%></td>
<td><%# eval("ord_time")%></td>
<td><a href="ordersdetail.aspx?ord_no=<%# eval("ord_no")%>">查看</a> </td>
</tr>
</itemtemplate>
</asp:datalist>
</tbody>
</table>
</p>
<p class="fenye">
<%-- 分页控件--%>
<center>
<webdiyer:aspnetpager id="aspnetpagernotice" runat="server" currentpagebuttonclass="cpb"
width="570px" showpageindexbox="always" pagesize="16"
firstpagetext="首页" lastpagetext="尾页" prevpagetext="上页" nextpagetext="下页"
onpagechanged="aspnetpagernotice_pagechanged"
currentpagebuttonstyle="color:#f60" numericbuttoncount="6" font-bold="false"
font-names="微软雅黑">
</webdiyer:aspnetpager>
</center>
</p>
再来看看cs文件代码:
复制代码
public partial class ordersmanage : system.web.ui.page
{
/// <summary>
/// 单页面中信息数量
/// </summary>
private int orders_limit = 16;
protected void page_load(object sender, eventargs e)
{
if (!ispostback)
{
refresh();
}
}
public void refresh()
{
using (blls o = new blls())
{
/*统计订单数量*/
string strsql = "select count(*) from orders";
dataset myds = o.select(strsql);
aspnetpagernotice.recordcount = convert.toint32(myds.tables[0].rows[0][0].tostring());
/*取前n条数据*/
string strsql1 = "select top(@p0) * from orders order by ord_id";
this.orders_list.datasource = o.select(strsql1, orders_limit);
this.orders_list.databind();//datalist绑定数据源
}
}
protected void aspnetpagernotice_pagechanged(object sender, eventargs e)
{
using (blls category = new blls())
{
string strsql2 = "select top (@p0) * from orders where ord_id not in ( select top (@p1) ord_id from orders order by ord_id) order by ord_id";
orders_limit = aspnetpagernotice.pagesize;//单页面订单显示数目
int start = aspnetpagernotice.startrecordindex - 1;
this.orders_list.datasource = category.select(strsql2, orders_limit, start);
this.orders_list.databind();
}
}
}
上一篇: 自媒体应该如何选择自媒体平台?