• 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();
            }
        }
    }
    喜欢的朋友请帮忙点个赞!!!
  • 相关阅读:
    iBatis.Net(4):DataMapper API
    【转】一步一步学Linq to sql(七):并发与事务
    【转】一步一步学Linq to sql(五):存储过程
    iBatis.Net(5):Data Map
    【转】一步一步学Linq to sql(三):增删改
    iBatis.Net(6):Data Map(深入)
    【转】一步一步学Linq to sql(四):查询句法
    【转】一步一步学Linq to sql(二):DataContext与实体
    .NET自动字符编码识别程序库 NChardet
    SQL UNIQUE Constraint
  • 原文地址:https://www.cnblogs.com/mchuang/p/5424689.html
Copyright © 2020-2023  润新知