zoukankan      html  css  js  c++  java
  • ASP-----分页功能的实现

    WEB 分页功能的实现
    后端C#代码部分:
    // 建立Linq 数据库的连接
    private MYDateDataContext context = new MYDateDataContext();

    // 设定每页几条数据
    private const int PAGESIZE = 3;

    //获取总的页数
    public int GetPageNo()
    {
    int PageNo =(int) Math.Ceiling(context.Car.Count()/PAGESIZE*1.0);
    return PageNo;
    }

    //获取指定页信息的方法
    public List<Car> GetPageCar( int PageNo)
    {
    //skip(每页固定行数*要求第几页-1).take(几行数据)
    var mimi = context.Car.Skip(PAGESIZE * PageNo - 1).Take(PAGESIZE);
    return mimi.ToList();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    int nowpage = 1;
    if( Request["pageno"]!=null)
    {
    nowpage = Convert.ToInt32(Request["pageno"]);
    }
    List<Car> list = GetPageCar(nowpage);

    // 给repeater 绑定数据源
    Repeater1.DataSource = list;// 获取数据源
    Repeater1.DataBind();// 绑定数据源

    // 给hyup hydown 绑定数据

    // 获取列表分页的最大值;
    int Pageno = GetPageNo();

    // 如果当前页为最大值 向上的键不可用
    if (Pageno == nowpage)
    {
    hydown.Enabled = false;
    }
    else
    {
    hydown.Enabled = true;
    hydown.NavigateUrl = "web1.aspx?pageno=" + (nowpage + 1).ToString();
    }
    if (nowpage == 1)
    {
    hyup.Enabled = false;
    }
    else
    {

    hyup.Enabled = true;
    hyup.NavigateUrl = "web1.aspx?pageno=" + (nowpage - 1).ToString();
    }

    //给首页 绑定数据
    hyfirst.NavigateUrl = "web1.aspx?pageno=1";
    // 给尾页绑定数据
    hyend.NavigateUrl = "web1.aspx?pageno=" + GetPageNo().ToString();

    }

    //跳转功能实现
    protected void Button1_Click(object sender, EventArgs e)
    {
    int lenth = TextBox1.Text.Trim().Length;

    // 将页面输入的值读取出来
    if (lenth!=0 )
    {
    int Gono = Convert.ToInt32(TextBox1.Text);


    if (Gono < 1)
    {
    // 如果要跳转的页面小于实际页数 跳转到本页
    Response.Redirect("web1.aspx");// 跳转的指定页

    }
    else if (Gono > GetPageNo())
    {
    Response.Redirect("web1.aspx?pageno=" + GetPageNo());
    }
    else
    {
    Response.Redirect("web1.aspx?pageno=" + Gono);


    }
    }
    else
    Response.Redirect("web1.aspx");


    }

    前段设计部分:
    注意点:HyperLink 超链接
    HyperLink 控件用于创建超链接;

  • 相关阅读:
    [转]MS SQL Server数据库事务锁机制分析
    【z】TCP/IP 网络基础 (v 0.2b)
    理解 SET CHAINED command not allowed within multistatement transaction.
    inux 设置系统时间和硬件时间
    Java IO测试样例字节流字符流
    【转】memcached完全剖析–1. memcached的基础
    【原】squid简单应用
    jstl字符串处理
    位图异或操作
    多个线程的同步执行,优先级控制
  • 原文地址:https://www.cnblogs.com/woniu-net/p/4715442.html
Copyright © 2011-2022 走看看