• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

CAML Query with Contains not working

I have a list called wraps with 12 items, no matter what I search using the following query, it always returns me the 12 items, so its not working correctly.

I debugged and the variable tag is OK.

  SPSite site = SPContext.Current.Site;
                // get the list
                SPList lstTagList = site.RootWeb.Lists.TryGetList("Wraps");
                if (lstTagList != null)
                {
                    // Try to find the item I want
                    SPQuery query = new SPQuery();
                    query.Query = "<Query><Where><Contains><FieldRef Name='Agenda_x0020_Tags' /><Value Type='Text'>" + tag + "</Value></Contains></Where></Query>";
                    SPListItemCollection foundItems = lstTagList.GetItems(query);
                    DataView dv = new DataView(foundItems.GetDataTable());
                    PagedDataSource page = new PagedDataSource();
                    page.AllowCustomPaging = true;
                    page.AllowPaging = true;
                    page.DataSource = dv;
                    page.PageSize = 10;
                   
                    WrapsRepeater.DataSource = page;
                    WrapsRepeater.DataBind();
0
LuisEstebanValencia
Asked:
LuisEstebanValencia
  • 2
1 Solution
 
KoenVostersCommented:
navdeep maybe read the question?

Luis you are probably using the querybuilder of U2U. You need to remove the <query> tags from your query.
0
 
LuisEstebanValenciaAuthor Commented:
Navdeep didnt event read the question. He think that just pasting an url would give him the points, you did the homework.

Thank you
0
 
KoenVostersCommented:
gl at m* ;-)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now