首页 > 代码库 > 分页展示

分页展示

技术分享

HTML技术分享

 

技术分享
当前第【<asp:Label ID="Label_Now" runat="server" Text="Label"></asp:Label>】页&nbsp;&nbsp;            共【<asp:Label ID="Label_Max" runat="server" Text="Label"></asp:Label>】页&nbsp;&nbsp;            &nbsp;&nbsp;            <asp:Button ID="btn_first" runat="server" Text="首页" />            &nbsp;&nbsp;                        <asp:Button ID="btn_prev" runat="server" Text="上一页" />            &nbsp;&nbsp;                        <asp:Button ID="btn_next" runat="server" Text="下一页" />            &nbsp;&nbsp;                        <asp:Button ID="btn_lest" runat="server" Text="末页" />            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>            <asp:Button ID="Button1" runat="server" Text="跳转" />
View Code
技术分享
    public List<Warehouse> selects(int count,int NowPage)    {        List<Warehouse> war = new List<Warehouse>();        cmd.CommandText = "select top "+count+"  * from Warehouse WHERE ids NOT IN (SELECT TOP "+(NowPage-1)*count+" ids FROM Warehouse)";        conn.Open();        SqlDataReader dr = cmd.ExecuteReader();        if (dr.HasRows)        {            while (dr.Read())            {                Warehouse ware = new Warehouse();                ware.ids = Convert.ToInt32(dr[0].ToString());                ware.name = dr[1].ToString();                ware.Unit = Convert.ToDouble(dr[2].ToString());                ware.Number = Convert.ToInt32(dr[3].ToString());                ware.dtime = Convert.ToDateTime(dr[4].ToString());                ware.Shelf = Convert.ToInt32(dr[5].ToString());                ware.jname = dr[6].ToString();                ware.dianhua = dr[7].ToString();                war.Add(ware);            }        }        conn.Close();        return war;    }
实体类
技术分享
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class logo : System.Web.UI.Page{    public string asc = null;    int count = 5;//一页要显示的条数    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            Label_Now.Text = "1";            Label_Max.Text = Max().ToString();            Repeater1.DataSource = new WarehouseDate().selects(count, 1);            Repeater1.DataBind();            btn_prev.Enabled = false;            int max = Max();            DropDownList1.Items.Clear();            for (int i = 1; i <= max; i++)            {                DropDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));            }        }        #region        asc = Request["ppp"];        Label1.Text = asc;        if (Request.Cookies["name"] != null)        {            Label1.Text = Request.Cookies["name"].Value;        }        else            Response.Redirect("Default.aspx");        Label1.Text += "登录成功,欢迎你!";        #endregion        DropDownList1.TextChanged += DropDownList1_TextChanged;        DropDownList1.AutoPostBack = true;        btn_lest.Click += btn_lest_Click;//末页        btn_next.Click += btn_next_Click;//下一页        btn_first.Click += btn_first_Click;//首页        btn_prev.Click += btn_prev_Click;//上一页        Button1.Click += Button1_Click;//跳转    }    void DropDownList1_TextChanged(object sender, EventArgs e)    {        //获取当前页,计算要看的下一页的页号;        int nextpage = Convert.ToInt32(DropDownList1.SelectedValue);        //判断是否有下一页        //if(nextpage>Max())        //{        //    return;        //}        if (nextpage <= 1)        {            btn_prev.Enabled = false;        }        else        {            btn_prev.Enabled = true;        }        if (nextpage >= 12)        {            btn_next.Enabled = false;        }        else            btn_next.Enabled = true;        //按照获取的页数绑定相应的页数        Repeater1.DataSource = new WarehouseDate().selects(count, nextpage);        Repeater1.DataBind();        //修改显示页数        Label_Now.Text = nextpage.ToString();    }    void Button1_Click(object sender, EventArgs e)    {        //获取当前页,计算要看的下一页的页号;        int nextpage = Convert.ToInt32(DropDownList1.SelectedValue);        //判断是否有下一页        //if(nextpage>Max())        //{        //    return;        //}        if (nextpage <= 1)        {            btn_prev.Enabled = false;        }        btn_next.Enabled = true;        //按照获取的页数绑定相应的页数        Repeater1.DataSource = new WarehouseDate().selects(count, nextpage);        Repeater1.DataBind();        //修改显示页数        Label_Now.Text = nextpage.ToString();    }    void btn_prev_Click(object sender, EventArgs e)    {        //获取当前页,计算要看的下一页的页号;        int nextpage = Convert.ToInt32(Label_Now.Text) - 1;        //判断是否有下一页        //if(nextpage>Max())        //{        //    return;        //}        if (nextpage <= 1)        {            btn_prev.Enabled = false;        }        btn_next.Enabled = true;        //按照获取的页数绑定相应的页数        Repeater1.DataSource = new WarehouseDate().selects(count, nextpage);        Repeater1.DataBind();        //修改显示页数        Label_Now.Text = nextpage.ToString();        DropDownList1.Text = nextpage.ToString();    }    void btn_first_Click(object sender, EventArgs e)    {        //按照获取的页数绑定相应的页数        Repeater1.DataSource = new WarehouseDate().selects(count, 1);        Repeater1.DataBind();        //修改显示页数        Label_Now.Text = "1";        btn_next.Enabled = true;        btn_prev.Enabled = false;    }    void btn_next_Click(object sender, EventArgs e)    {        //获取当前页,计算要看的下一页的页号;        int nextpage = Convert.ToInt32(Label_Now.Text) + 1;        //判断是否有下一页        //if(nextpage>Max())        //{        //    return;        //}        if (nextpage >= Max())        {            btn_next.Enabled = false;        }        //按照获取的页数绑定相应的页数        Repeater1.DataSource = new WarehouseDate().selects(count, nextpage);        Repeater1.DataBind();        btn_prev.Enabled = true;        //修改显示页数        Label_Now.Text = nextpage.ToString();        DropDownList1.Text = nextpage.ToString();    }    void btn_lest_Click(object sender, EventArgs e)    {        //按照获取的页数绑定相应的页数        Repeater1.DataSource = new WarehouseDate().selects(count, Max());        Repeater1.DataBind();        //修改显示页数        Label_Now.Text = Max().ToString();        btn_next.Enabled = false;        btn_prev.Enabled = true;        DropDownList1.Text = Max().ToString();    }    /// <summary>    /// 获取到最大的页数    /// </summary>    /// <returns></returns>    public int Max()    {        List<Warehouse> wlist = new WarehouseDate().select();        double End2 = Convert.ToInt32(Math.Ceiling(wlist.Count / (count * 1.0)));        int End = Convert.ToInt32(End2);        return End;    }}
C#

 

分页展示