Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:23:39+00:00 2026-05-25T12:23:39+00:00

I have created a CAML query to get some particular items on a list,

  • 0

I have created a CAML query to get some particular items on a list, that contains OR:

 <Or>
    <Eq><FieldRef Name='Title'/><Value Type='Text'>tileA</Value></Eq>
    <Eq><FieldRef Name='Title'/><Value Type='Text'>titleB</Value></Eq>
 </Or>

Now the query works fine if I pass it to list.GetItems() metod, but it doesn’t work when I use it like that:

SPContext.Current.List.DefaultView.Query = myStringQuery;
SPContext.Current.List.DefaultView.Update();

I place the code in a webpart (Page_Load()), that is added to the list, the code executes, but the view remains unfiltered. Anyone knows what might be the reason for that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:23:39+00:00Added an answer on May 25, 2026 at 12:23 pm

    Two things:

    First, make sure your CAML is wrapped in a Where element:

    <Where>
        <Or>
            <Eq><FieldRef Name='Title'/><Value Type='Text'>tileA</Value></Eq>
            <Eq><FieldRef Name='Title'/><Value Type='Text'>titleB</Value></Eq>
        </Or>
    </Where>
    

    Second, rearrange your code like this:

    SPView view = SPContext.Current.List.DefaultView;
    view.Query = myStringQuery;
    view.Update();
    

    I know the code blocks looks the same, but neither SPContext nor DefaultView use private fields. For example, here is the implementation of DefaultView:

    internal SPView DefaultView
    {
      get
      {
        if (this.m_iDefaultViewIndex == -1)
          return (SPView) null;
        else
          return this[this.m_iDefaultViewIndex];
      }
    }
    
    public SPView this[int iIndex]
    {
      get
      {
        if (iIndex < 0 || iIndex >= this.Count)
          throw new ArgumentOutOfRangeException();
        else
          return new SPView(this, this.m_arrViewSchema, iIndex);
      }
    }
    

    So with:

    SPContext.Current.List.DefaultView.Query = myStringQuery;
    SPContext.Current.List.DefaultView.Update();
    

    The first line sets the Query property of an instance of DefaultView while the second line calls Update on a new instance of the DefaultView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a list. And I need to get the text on the
I have created some forms using zendframework on my local machine that send the
Have created a custom navigation menu in wordpress that has some pages and some
Have created an attribute property in TableView1.h and pushing that attributes value to another
I have created a user defined type to contain some data that I will
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have created a webservice in .net 2.0, C#. I need to log some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.