SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
     "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>'Label1.Text'</Value>    </Eq></Where>";

I have not run this and checked yet, simply because I am quite sure it is not going to work. How exactly do I specify the syntax to compare and filter a list item[title] to a label.text Thanks

share|improve this question
string query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + Label1.Text + "</Value></Eq></Where>"; – sssreddy Mar 21 '12 at 14:36
@sssreddy you should post that as an answer... since it is. – RJ Cuthbertson Mar 21 '12 at 14:39
@sssreddy Thanks – user7400 Mar 21 '12 at 14:43
up vote 2 down vote accepted

The only thing you need to do to make that query valid, is ensure the Label1.Text uses the actual value, rather than the text 'Label1.Text'

In C# it would be something like

String camlQuery = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + Label1.Text + "</Value></Eq></Where>";
share|improve this answer
Thanks for the reply – user7400 Mar 21 '12 at 14:43
And make sure to Encode Label1.Text so it can't contain < and other chars which might leave you open for CAML injection attacks – Per Jakobsen Mar 21 '12 at 14:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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