views:

345

answers:

2

How do you order items when you override the QueryOverride property of the Content Query Web Part?

I have been given responsibility for a Web Part which extends the Content Query Web Part. The QueryOverride property of this Web Part is programmatically changed. Currently, the Web Part does not function as designed, as it does not order the items according to the appropriate field.

If I add an <OrderBy> node to the QueryOverride property I get an error message along the lines of 'something wrong with the query this web part is...' and the Content Query Web Part doesn't seem to have an OrderBy property which I could use instead.

The "QueryOverride property" part of this msdn article seems to suggest I should be able to add an <OrderBy> node to the QueryOverride but a number of web sites I've been reading suggest that this is not true.

So, how do you order items when you override the QueryOverride property of the Content Query Web Part?

+3  A: 

Does your QueryOverride statement contain any Whitespace/linebreaks by any chance? I think I recall a while back having a situation where the QueryOverride needed to be all contained on one line, with no spaces between xml tags.

Weird I know, but try it out.

Also, for reference see the first community comment on the MSDN page http://msdn.microsoft.com/en-us/library/aa981241.aspx

Paul Lucas
I'll try removing the line breaks... but it works _with_ line breaks if I exclude the `<OrderBy>`... is that consistent with what you remember?
LeguRi
It does ring a bell actually!
Paul Lucas
There are no words to describe the infinite extents of your awesomeness.
LeguRi
* thinks about it a little more * and Good Lord, SharePoint is pile of rubbish!
LeguRi
I'm going to have to go ahead and agree with you Richard. The XML fetish with this product is completely out of hand.
Gurdas Nijor
The xml thing wouldn't be so bad if it behaved like xml. Well-formed xml is well formed xml IMHO. Another thing that gets me are "case-sensitive guids" that I come across from time to time.
Paul Lucas
A: 

THanks for this. Just to clarify, there should be no white spaces before or after the tags as well.

This did not work:

<![CDATA[
   <OrderBy><FieldRef Name="EndDate" Ascending="False"/></OrderBy>
   <Where>

But this did:

<![CDATA[<OrderBy><FieldRef Name="EndDate" Ascending="False"/></OrderBy><Where>

Wierd but thanks again for posting this answer, it saved me a lot of time.

Russell Lindell