zoukankan      html  css  js  c++  java
  • 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;

            }

  • 相关阅读:
    DEVOPS技术实践_02:jenkins自动构建项目
    DEVOPS技术实践_01:jenkins集成平台
    nginx和keeplive实现负载均衡高可用
    web简易MP3播放插件 Aplayer篇章一
    龙珠MAD-视频列表(收集更新)
    使用咪咕云做C站视频直链源
    自翻唱龙珠超OP2【限界突破X幸存者】
    龙珠超的新OP【限界突破×サバイバー】
    [盘点]现今热门的h5网游
    一个简单的“贪吃蛇”小游戏
  • 原文地址:https://www.cnblogs.com/xihong2014/p/4227658.html
Copyright © 2011-2022 走看看