2

I have a problem with filtering list items using CAML

I Have this list: Code - Text, Name - Text, Link - Text, Order No - Number, Parent - Lookup to this List. I want to filter all items where Parent is not selected (i.e none)

Here is my CAML query but it's not giving the right solution:

string camlquery = String.Format(@"<where>
                                                <Eq><FieldRef Name='{0}' /><Value Type='Lookup'></Value></Eq>
                                                </where>
                                               <OrderBy>
                                                <FieldRef Name='Order No'></FieldRef>
                                                </OrderBy>
                                               ", this.MenuItemParentField);

MenuItemParentField it's the name of the lookup column MenuItemParentField="Parent"

What is going wrong with my caml query

Any help would be appreciated

Thank you

1 Answer 1

5

Use IsNull Element (Query) instead of Eq Element (Query)

string camlquery = String.Format(@"<where> 
                                     <IsNull><FieldRef Name='Parent' /></IsNull> 
                                   </where> 
                                   <OrderBy> 
                                     <FieldRef Name='Order No'></FieldRef> 
                                   </OrderBy> 
                                   ", this.MenuItemParentField); 
2
  • What if you remove the OrderBy, thats not a right InternalName, sorry I didn't see that before Commented Jul 17, 2012 at 13:44
  • 1
    This is an old post, but it was the first result from a Google search. It DOES work, Milena, and you accepted it as the answer. I think you should remove the comment saying it isn't working, it is confusing to those of us who come here two years later.
    – CigarDoug
    Commented Sep 29, 2014 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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