SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As per title, is it possible (and how) to modify default view in code so that it display contents of the list grouped by one of it's columns?

I tried the following:

defaultView.Query = String.Format(@"<GroupBy collapse='true'>" +
                                          "<FieldRef Name='{0}' />" +
                                       "</GroupBy>", SPBuiltInFieldId.TaskDueDate);

but this doesn't seem to work.

share|improve this question

There are couple of ways to do it. 1. Access the view's schema XML and modify the query XML inside this. This can be achieved through SharePoint object model. 2. Use designer, generate the XSLT for the webpart and change the query appropriately.

share|improve this answer
please see my edit. I have tried 1 and 2 doesn't look like it's to do in code? – Sebastian Jun 28 '12 at 6:35
This seems to be fine, you might need to debug the code to check. Not able to comment by just looking at these two lines of code. – Manju Jun 29 '12 at 3:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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