Problem with linq on Gridview
-
Hi I have an object which is a collection, which is a collection, I use linq to group the data based upon a value, and then I bind the data to the gridview data source. This gives me a gridview per group, which is exactly what I want. However, when the gridview is displayed what I am seeing is one: not the correct number of rows for the first group, and two, more importantly I am seeing rows which should be in the next group. It is though it is not filtering correctly, or the gridview is not binding correctly. I have checked the linq in debug and seems fine, I have checked the data in the collection object, and this is fine. So, I am lost as to what is going on. Can anyone help me! Collection<DeptGroups> depts = this.Model.GetGroups(); var dept = (from deptToSelect in depts Select dept.name).Distinct(); foreach(string deptToFilter in dept) { var country = from worldRegion in depts where worldRegion.name = deptToFilter select worldRegion; gvDept.DataSource = country; }