在GridView中删除重复的行 [英] Remove duplication row in gridview

查看:164
本文介绍了在GridView中删除重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四列, facilities_id 名称日期我的 GridView控件。我的问题是,它在我的结果相同 facilities_id 。那么,如何可以解决它,任何人都可以帮我吗?谢谢..

在额外的,我希望能找到在GridView中前2排。的意思只是显示在顶部2行..
谢谢

  DataClassesDataContext DB =新DataClassesDataContext();
    VAR查询从db.Facilities P =
                加入db.Reservations V,而p.facilities_id等于v.facilities_id
                将C在v.reservation_id平等db.Reservation_Details
                c.resevation_id                其中,SqlMethods.Like(c.date,%+ DropDownList1.Text +%)
                新选择
                {
                    p.facilities_id,
                    p.name,
                    c.date,
                    数量= p.Reservations.Count()                };    GridView1.DataSource =查询;
    GridView1.DataBind();

下面是我的输出,如何去除相同facilities_id。

  facilities_id名日期数量
  F001 AA 2014年12月1日1
  F001 AA 2014年12月1日12
  F002 BB 2014年12月1日1
  F003 CC 2014年12月1日1

我希望能成为这个样子。

  facilities_id名日期数量
  F001 AA 2014年12月1日13
  F002 BB 2014年12月1日1
  F003 CC 2014年12月1日1


解决方案

这是code独特facilities_id。
我不知道你是从数据集或表中获取数据。

我有返回code这是指检索数据集中的code以及该数据集将是独一无二的。

和还您量将增加,但是facilities_id将不再重复。

  VAR销售从排=以ds.Tables [cartTable]。AsEnumerable()(写在这里您的表名,因为我不知道你的表名)
                    通过row.Field&LT组行;串>(facilities_id)到rowGroup
                    新选择
                    {
                        facilities_id = rowGroup.Key,                        命名=的string.join(,rowGroup.Select(行= GT; row.Field&下;串GT(。名称))是不同的()ToArray的()),                        日期=的string.join(,rowGroup.Select(行=> row.Field<串GT;(DATE))是不同的()ToArray的()。)                        价格=的string.join(,rowGroup.Select(行=> row.Field<&小数GT;(价格))是不同的()ToArray的()。)                        数量= rowGroup.Sum(R = GT; r.Field< INT>(量))                    };
我希望这code将是你......有用!!!!

I have four column, facilities_id, name, date and quantity for my gridview. My problem is it have same facilities_id in my result. So how can i settle it, anyone can help me? Thanks..

In additional, i hope can find the top 2 row in gridview. Mean just show up the top 2 row.. Thanks

    DataClassesDataContext db = new DataClassesDataContext();


    var query = from p in db.Facilities
                join v in db.Reservations on p.facilities_id equals v.facilities_id
                join c in db.Reservation_Details on v.reservation_id equals 
                c.resevation_id

                where SqlMethods.Like(c.date, "%" + DropDownList1.Text + "%")
                select new
                {
                    p.facilities_id,
                    p.name,
                    c.date,
                    Quantity = p.Reservations.Count()

                };

    GridView1.DataSource = query;
    GridView1.DataBind();

Here is my output, how to remove the same facilities_id.

facilities_id  name    date        quantity
  F001           aa    12/01/2014      1
  F001           aa    12/01/2014      12
  F002           bb    12/01/2014      1
  F003           cc    12/01/2014      1  

i hope can become like this.

facilities_id  name    date        quantity
  F001           aa    12/01/2014      13
  F002           bb    12/01/2014      1
  F003           cc    12/01/2014      1  

解决方案

This is the code for unique facilities_id. I dont know that you are getting data from dataset or table.

I have return a code which is retrieving the code in dataset and that dataset going to be unique.

And also your quantity will be added but facilities_id will not be repeated.

     var sells = from row in ds.Tables["cartTable"].AsEnumerable() ("Write here your table name as I dont know your table name ")
                    group row by row.Field<string>("facilities_id") into rowGroup
                    select new
                    {
                        facilities_id = rowGroup.Key,

                        name = string.Join(" ", rowGroup.Select(row => row.Field<string>("name")).Distinct().ToArray()),

                        date = string.Join(" ", rowGroup.Select(row => row.Field<string>("date")).Distinct().ToArray()),

                        price = string.Join(" ", rowGroup.Select(row => row.Field<decimal>("price")).Distinct().ToArray()),

                        Quantity = rowGroup.Sum(r => r.Field<int>("quantity")),

                    };


I hope this code will be useful to you......!!!!

这篇关于在GridView中删除重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆