zoukankan      html  css  js  c++  java
  • Webform 翻页查询.最主要理解这一句代码 return _Context.ChinaStates.Skip((nowpage

    查询里的方法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// CarBF 的摘要说明
    /// </summary>
    public class CarBF
    {
        private DataClassesDataContext _Context;
        public CarBF()
        {
            _Context = new DataClassesDataContext();
        }
        public List<Car> Select()
        {
            return _Context.Car.ToList();
        }
        public List<ChinaStates> Select1()
        {
            return _Context.ChinaStates.ToList();
        }
        //Take查询前五条
        public List<ChinaStates> Select2()
        {
            return _Context.ChinaStates.Take(5).ToList();
        }
    
        //nowpage是当前页,numbers是一页为几条数据.skip是跳过序列中指定数量的元素
        public List<ChinaStates> Select3(int nowpage,int numbers)
        {
            return _Context.ChinaStates.Skip((nowpage - 1) * numbers).Take(numbers).ToList();
        }
    }


    aspx.cs里的代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //List<Car> list = new CarBF().Select();
            //Cache.Insert("aaa",list);
            if (!IsPostBack)
            {
                bangding(1, 5);
            }
        }
        //点击首页
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
                bangding(1,5);       
       }
        public void bangding(int nowpage,int numbers)
        {
            List<ChinaStates> list = new CarBF().Select3(nowpage, numbers);
            Repeater1.DataSource = list;
            Repeater1.DataBind();
            TextBox1.Text = nowpage.ToString();
        }
        //点击尾页   
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            List<ChinaStates> list = new CarBF().Select1();
            if (list.Count%5==0)
            {
                bangding(list.Count/5,5);
            }
            else if (list.Count%5!=0)
            {
                bangding(list.Count/5+1,5);
            }
        }
        //点击上一页
        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            int nowpage = Convert.ToInt32(TextBox1.Text);
            if (Convert.ToInt32(TextBox1.Text) > 1)
            {
                bangding(nowpage - 1, 5);
            }
            else
            {
                LinkButton3.Enabled = false;
            }
        }
        //点击下一页
        protected void LinkButton4_Click(object sender, EventArgs e)
        {
            List<ChinaStates> list = new CarBF().Select1();
            int count = list.Count / 5;
            if (Convert.ToInt32(TextBox1.Text) <= count)
            {
                int nowpage = Convert.ToInt32(TextBox1.Text);
                bangding(nowpage + 1, 5);
            }
            else
            {
                LinkButton4.Enabled = false;
            }
        }
        //当点击转到页的时候
        protected void LinkButton5_Click(object sender, EventArgs e)
        {
            List<ChinaStates> list = new CarBF().Select1();
            if (Convert.ToInt32(TextBox1.Text) > list.Count / 5 + 1)
            {
                TextBox1.Text = null;
                Literal1.Text = "页数超出范围";
            }
            else
            {
                int count = Convert.ToInt32(TextBox1.Text);
                bangding(count, 5);
            }
        }
    }


    效果图

  • 相关阅读:
    hive中如何查询除了其中某个字段剩余所有字段
    查找出不同环境下同一张表的数据差异
    pycharm中导入包失败的解决办法
    hive如何获取当前时间
    python-匿名函数
    Tensorflow报错:OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized.
    Tensorflow中Tensor对象的常用方法(持续更新)
    Numpy中的广播机制,数组的广播机制(Broadcasting)
    重装conda
    matplotlib作图一例
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4694215.html
Copyright © 2011-2022 走看看