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 控件用于创建超链接;

  • 相关阅读:
    Integration Services 学习(4):包配置
    Integration Services 学习(3)
    AsyncTask的使用
    asp.net下实现支持文件分块多点异步上传的 Web Services
    wcf/web service 编码
    c# 接发邮件2
    Integration Services 学习
    使用AChartEngine画柱状图
    Cocos2d开发系列(五)
    灵活使用XMultipleSeriesRenderer设置自定义的轴标签
  • 原文地址:https://www.cnblogs.com/woniu-net/p/4715442.html
Copyright © 2011-2022 走看看