zoukankan      html  css  js  c++  java
  • LINQ 语句实现分页

    表名为people;

    int a=10;    --每页放10行数据;

    构造函数内:

    using (DBDataContext con = new DBDataContext())
                {
                    List<people> pl = con.people.Skip(0).Take(a).ToList();
                    foreach (people x in pl)
                    {
                        ListViewItem l = new ListViewItem();
                        l.Text = x.ids.ToString();
                        l.SubItems.Add(x.name);
                        l.SubItems.Add(x.pwd);
                        l.SubItems.Add(x.nickname);
                        l.SubItems.Add(x.sex.Value ? "" : "");
                        l.SubItems.Add(x.nation.nationname);
                        l.SubItems.Add(x.birthday.Value.ToString("yyyy年MM月dd日"));
                        listView1.Items.Add(l);
                    }
                }

    查询最大页数:

    public int maxy()
            {
                int x = 0;
                using (DBDataContext con = new DBDataContext())
                {
                    x = con.people.ToList().Count;
                    if (x % 10 == 0)
                    {
                        x = x / 10;
                    }
                    else
                    {
                        x = x / 10 + 1;
                    }
                }
                return x;
            }

    上一页按钮:

     private void button1_Click(object sender, EventArgs e)
            {
                if (label2.Text != "1")
                {
                    listView1.Items.Clear();
                    using(DBDataContext con=new DBDataContext())
                    {
                        List<people> pl = con.people.Skip((Convert.ToInt32(label2.Text) - 2) * a).Take(a).ToList();
                        foreach (people x in pl)
                        {
                            ListViewItem l = new ListViewItem();
                            l.Text = x.ids.ToString();
                            l.SubItems.Add(x.name);
                            l.SubItems.Add(x.pwd);
                            l.SubItems.Add(x.nickname);
                            l.SubItems.Add(x.sex.Value ? "" : "");
                            l.SubItems.Add(x.nation.nationname);
                            l.SubItems.Add(x.birthday.Value.ToString("yyyy年MM月dd日"));
                            listView1.Items.Add(l);
                        }
                    }
                    int i = Convert.ToInt32(label2.Text);
                    i--;
                    label2.Text = i.ToString();
                }
            }

    下一页按钮:

    private void button2_Click(object sender, EventArgs e)
            {
                int y = maxy();
                if (Convert.ToInt32(label2.Text) != y)
                {
                    listView1.Items.Clear();
                    using (DBDataContext con = new DBDataContext())
                    {
                        List<people> pl = con.people.Skip(Convert.ToInt32(label2.Text) * a).Take(a).ToList();
                        foreach (people x in pl)
                        {
                            ListViewItem l = new ListViewItem();
                            l.Text = x.ids.ToString();
                            l.SubItems.Add(x.name);
                            l.SubItems.Add(x.pwd);
                            l.SubItems.Add(x.nickname);
                            l.SubItems.Add(x.sex.Value ? "" : "");
                            l.SubItems.Add(x.nation.nationname);
                            l.SubItems.Add(x.birthday.Value.ToString("yyyy年MM月dd日"));
                            listView1.Items.Add(l);
                        }
                    }
                    int i = Convert.ToInt32(label2.Text);
                    i++;
                    label2.Text = i.ToString();
                }
            }
  • 相关阅读:
    [转]Linux里的2>&1究竟是什么
    一段shell脚本分析
    [整理]Linux Crontab命令总结
    random seed()函数
    clear命令新认识
    泛型与发射初探,获取当前代码所在的行
    tomcat集群(转)
    查看本地电脑的端口及对应的使用程序
    信息摘要算法小试牛刀
    Linux非root用户安装jdk和tomcat(转)
  • 原文地址:https://www.cnblogs.com/m110/p/8037089.html
Copyright © 2011-2022 走看看