I have custom list. with calculated column Department Group.

Department group column takes first left letter of title columns in uppercase.

enter image description here

using SPListItemCollection I'm able to get all items. but now I am trying to bind the group record in different table.


         all record of Department group : A in one table
         all record of Department group : B in one table

so I think for that I need grouping for in SPListItemCollection

I am stuck here help me.

my sample code

   using (SPSite site = new SPSite(SPContext.Current.Web.Url))
            using (SPWeb web = site.OpenWeb())
                SPList list = web.Lists.TryGetList(listName);

                if (list != null) { 
                SPQuery query = new SPQuery();
                query.Query = " <Where>"+
                              "<FieldRef Name='DepartmentGroup' />"+
                              "<FieldRef Name='DepartmentGroup' Ascending='True' />"+

                SPListItemCollection items = list.GetItems(query);
  • I think GroupBy won't be helpful if you are looking for making it to different tables. – Gaurravs Sep 19 '16 at 5:11
  • How many Departments you can have? Is it fix or not sure?? – Gaurravs Sep 19 '16 at 5:12
  • I have department from A To Z – Akshay Dattatray Nangare Sep 19 '16 at 5:46
  • so suggest better options for group by.. – Akshay Dattatray Nangare Sep 19 '16 at 5:48

You can try adding a reference to System.Linq , filter your SPListItemCollection using a Where Linq clause and bind the result to a table as desired.


var deptA = items.Cast<SPListItem>().Where(p => p.DepartmentGroup== "A")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.