zoukankan      html  css  js  c++  java
  • c# Repeater 和 AspNetPager

    1. 首先我们要引用一下AspNetPager.dll

    2. 然后新建一个页面,在页面头部加上,这里很重要!!!

      <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

    3. 前台代码

      

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="KXL.Web.WebForm1" %>
    
    <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table>
                <tbody>
                    <asp:Repeater ID="Repeater1" runat="server">
                        <ItemTemplate>
                            <tr>
                                <td class="am-hide-sm-only">
                                    <%#Eval("ID")%>
                                </td>
                                <td class="am-hide-sm-only">
                                    <%#Eval("UserName")%>
                                </td>
                                <td class="am-hide-sm-only">
                                    <%#Eval("UserPhone")%>
                                </td>
                                <td class="am-hide-sm-only">
                                    <%#Eval("Password")%>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
            </table><asp:Label ID="CountNumber" runat="server"></asp:Label>
            条记录
            <div class="am-fr">
                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" HorizontalAlign="Center"
                    AlwaysShow="True" PageSize="3" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
                    OnPageChanged="AspNetPager1_PageChanged">
                </webdiyer:AspNetPager>
            </div>
        </div>
        </form>
    </body>
    </html>  

    4. 后台代码

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace KXL.Web
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!IsPostBack)
                {
                    Bind();
                }
            }
            /// <summary>
            /// 绑定数据
            /// </summary>
            public void Bind()
            {
                int shang = AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1) + 1;
                int xia = AspNetPager1.PageSize * AspNetPager1.CurrentPageIndex;
                string where = "1=1 ";
                AspNetPager1.RecordCount = new BLL.ss().GetRecordCount(where);
                this.CountNumber.Text = AspNetPager1.RecordCount.ToString();
                Repeater1.DataSource = new BLL.ss().GetListByPage(where, "", shang, xia);
                Repeater1.DataBind();
            }
            /// <summary>cuxiao
            /// 分页
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void AspNetPager1_PageChanged(object sender, EventArgs e)
            {
                Bind();
            }
        }
    }
    喜欢的朋友请帮忙点个赞!!!
  • 相关阅读:
    VMWare 桥接模式
    什么是交叉编译,为什么要使用交叉编译
    最常用的四种大数据分析方法
    C#的Dispose模式复习
    Oracle Data Provider for .NET Support for Microsoft .NET Core
    微软发布了量子计算开发包
    关于Oracle分区表的理解
    html 中video标签视频不自动播放的问题
    input 修改placeholder颜色
    正则表达式 手机号验证、邮箱验证、6~16位数字加字母组合、身份证号码验证
  • 原文地址:https://www.cnblogs.com/mchuang/p/5424689.html
Copyright © 2011-2022 走看看