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

第一次写博客,其实注册挺久的了,一直不知道写些什么好,原因是自己菜鸟一个,知识浅陋,不好出来献丑。

但是慢慢接触的多了,总觉得有些东西是不是该写一写,跟分享一下!不敢说对大家都有用,互相学习,也权当是给自己学习的路上留下一点印记吧!

废话不说了,进入主题:

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

先来看aspx文件代码

<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文件代码:

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

}

好了,有了上面的代码,看一下效果图:

 

好了,基本上是大功告成!!

但是如果要去挑一些毛病的话,还是存在一些问题的:

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

还请大神指点一二!!

 

 

转载于:https://www.cnblogs.com/linghao19920915/p/3464057.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值