• 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);
            }
        }
    }


    效果图

  • 相关阅读:
    微信支付开发(12) 认清微信支付v2和v3
    教爸爸妈妈用微信
    微信公众平台开发(103) 四六级成绩查询
    微信支付开发(11) Native支付
    微信公众平台开放设备接入能力
    微信公众平台开发(102) 模板消息
    微信支付开发(10) 全网发布
    微信小店开发(3) 自定义菜单加入维权
    openssl下载
    使用PHP QR Code生成二维码
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4694215.html
Copyright © 2020-2023  润新知