.net分页功能实现

html代码

 <div id="policy">
                    <asp:Repeater ID="Repeater1" runat="server">
                        <ItemTemplate>
                            <ul id="tt" class="yb_list notice_policy_list">


                                <li class="notice_policy_item flex">
                                    <div id="dtime" class="date"><%#DateTime.Parse(Eval("XXData").ToString()).ToString("MM-dd")%></div>
                                    <a id="title" class="notice_policy_text" href="xinwenxiangqing/xinwenxq.aspx?id=<%#Eval("ID")%>"><%#Eval("Tatle")%></a>
                                </li>


                            </ul>

                        </ItemTemplate>
                    </asp:Repeater>

                    <div class="btns">
                        <a id="xia2" runat="server" href="javascript:down();">下一页</a>
                        <a id="shang2" runat="server" href="javascript:up();">上一页</a>

                    </div>
                </div>
            </div>
        </div>
        <asp:HiddenField ID="hfMemberID" runat="server" />
        <asp:HiddenField ID="bbb" runat="server" />
        <asp:HiddenField ID="aaa" runat="server" />

js代码

  <script>
           
            function up() {
                var pageindex = $('#aaa').val();


                pageindex = parseInt(pageindex) - 1;

                location.href = 'policy.aspx?cmd=' + pageindex;
            };
            function down() {
                var pageindex = $('#aaa').val();

                pageindex = parseInt(pageindex) + 1;


                location.href = 'policy.aspx?cmd=' + pageindex;
            }
        </script>

.cs代码

public partial class policy : System.Web.UI.Page
    {
        protected string XXData = "";
        protected string sql2 = "";
        protected string biaoti = "";
        
        protected DataTable dt = new DataTable();
        protected DataTable dt2 = new DataTable();
        public static int cmd = 0;
      
        public static int pageStart = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                biaoti = this.Label1.Text;

               
                cmd =Convert.ToInt32( Request["cmd"]??"1");

                aaa.Value = cmd.ToString();
                policyList(cmd);
               


            }
        }

        public void policyList(int cmd)
        {
         
            sql2 = @"select * from t_FaBuXinXi where XXType='" + biaoti + "' and Tatle='" + biaoti + "'";
            dt2 = DbHelperSQL.QueryDT(sql2);


            int pageStart = cmd;
            int pageCont = 5; 
            int start = (pageStart - 1) * pageCont;
            if (start == 0)
            {
                shang2.Visible = false;
            }
                 
            int end = (pageStart * pageCont) - 1;
            if (cmd == 1)
            {
                end = 5;
            }
            string sql = @"select * from ( select ROW_NUMBER() over(order by XXData desc) as row,* from t_FaBuXinXi where XXType='" + biaoti + "' )r  where r.row between  " + start + " and " + end;

            dt = DbHelperSQL.QueryDT(sql);
            if (dt.Rows.Count < 5)
            {
                xia2.Visible = false;
            }
            if (dt.Rows.Count == 0)
            {
                Response.Write("<script language=javascript>history.go(-1);</script>");
                Response.Write("<script language=javascript>alert('已经是最后一页');</script>");
                Response.End();
            }
                  
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
          
           
        }

每页显示5条。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值