html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

Asp.net下用AspNetPager分页控件对DataList进行分页_.NET教程_编程技术

[ ] 已经帮助:人解决问题

asp.net下用AspNetPager分页控件对DataList进行分页

最近在做一个兼顾前后台的项目,用到了很多都是用DataList绑定数据和用AspNetPager实现对数据进行分页管理的知识

先来看aspx文件代码TupHTML5中文学习网 - HTML5先行者学习网

<div 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>             </div>            <div 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>           </div>

  再来看看cs文件代码:TupHTML5中文学习网 - HTML5先行者学习网

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();        }    }}

好了,有了上面的代码,看一下效果图:TupHTML5中文学习网 - HTML5先行者学习网

 TupHTML5中文学习网 - HTML5先行者学习网

TupHTML5中文学习网 - HTML5先行者学习网

好了,基本上是大功告成!!TupHTML5中文学习网 - HTML5先行者学习网

但是如果要去挑一些毛病的话,还是存在一些问题的:TupHTML5中文学习网 - HTML5先行者学习网

我想在下页前面始终显示最后一页(第20页)的按钮,我也查看了属性却不知道怎么实现,网上倒是有一些自己写方法实现的资料;TupHTML5中文学习网 - HTML5先行者学习网

TupHTML5中文学习网 - HTML5先行者学习网
TupHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助