• gridview 绑定多个格式相同的数据源(数据查询合并)


    在做项目时,要求在同一个GridView中同时显示不同分组中的前若干条数据

    几个技术要点:

    1、数据分组,本方法中未用group by

    2、几个结果格式相同的查询合并绑定

    3、取查询结果的前或后若干条数据

            public int BindLiftData()

            {

                int count = 0;

                using (MySqlConnection conn = new MySqlConnection(dbServer))

                {

                    FrDData db = new FrDData(conn);

                    List<int> ids = new List<int>();

                    var item =  from i in db.Items

                                join p in db.ProgS on i.ProgID equals p.ID

                                where p.State == 1 && i.Type == "升程"

                                select new {i.ID};

                    bool isFirst = true;

                    int firstID =0;

                    foreach (var i in item)

                    {

                        if (isFirst)

                        {

                            firstID = i.ID;

                            isFirst = false;

                        }

                        else

                            ids.Add(i.ID);

                    }

                    var q = (from i in db.Items

                             join l in db.Lifts on i.ID equals l.ItemID

                             where i.ID == firstID

                             orderby l.ID descending

                             select new { i.ID, i.Name, l.Angle, i.Stole, l.Lift }).Take(3).ToList();

                    foreach(var x in ids)

                    {

                        var r = (from i in db.Items

                                 join l in db.Lifts on i.ID equals l.ItemID

                                 where i.ID == x

                                 orderby l.ID descending

                                 select new { i.ID, i.Name, l.Angle, i.Stole, l.Lift }).Take(3).ToList();

                        q.AddRange(r);

                    }

                    gvLift.DataSource = q;

                    count = q.Count;         

                }

                return count;

            }

  • 相关阅读:
    what's the python之if判断、while循环以及for循环
    what's the python之基本运算符及字符串、列表、元祖、集合、字典的内置方法
    what's the python之变量、基本数据类型
    what's the python之python介绍
    计算机基础系列之网络基础——网络协议
    计算机基础系列之何为操作系统
    计算机基础系列之计算机硬件
    EXT3_DX_ADD_ENTRY: DIRECTORY INDEX FULL!
    无shell情况下的mysql远程mof提权利用方法详解
    /bin/rm: Argument list too long解決方法
  • 原文地址:https://www.cnblogs.com/xihong2014/p/4227658.html
Copyright © 2020-2023  润新知