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.


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.

  • 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 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.