1 out of 4 rated this helpful - Rate this topic

CHOICE Element (List)

Windows SharePoint Services 3

Used to define a choice within a Choice field.


<CHOICES>
  <CHOICE
    Value = "Text">
  </CHOICE>
  <CHOICE
    Value = "Text">
  </CHOICE>
  ...
</CHOICES>
Attribute Description

Value

Optional Text. Can be used to specify an identifier for the choice.

Minimum: 0

Maximum: Unbounded

Remember that CAML is case-sensitive; the CHOICE and CHOICES elements are in all capital letters.

The CHOICE element contains the value within its body.

The following example defines a Choice field with three choices.

<CHOICES>
  <CHOICE>Not Started</CHOICE>
  <CHOICE>In Progress</CHOICE>
  <CHOICE>Completed</CHOICE>
</CHOICES>
    
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Value attribut may actually do harm.
I was using the Value attribute and made one other change in the feature. Value was ignored but it also invalidated the feature element prevented the entire feature from updating. You will not see it if you just add the Value attribute. Add the Value attribute and change the description of something and you will not see the update to the subscription.
CAML Rendering and the Value attribute
Funny thing is that the CAML rendering code for the Choice field does reference the Value attribute:

<ForEach Select="CHOICES/CHOICE">
...
<Property Select="Value"/>
...
Value - a good idea but nothing more
After hours of investigation, I think it's not possible to define a value for a choice. The representing object SPFieldChoice has a member Choices which is nothing else than a string collection. The above idea is nice - but does not work...

The only way I see is to create a own type with his own control template inherited from BaseFieldControl.

This documentation is misleading...

Reading this, you might be led to believe that you could create a CHOICES collection like this to have SharePoint use value codes on the back-end of its DropDownList's options tag in HTML. Like this:

<CHOICES>
<CHOICE Value="MD">Maryland</CHOICE>
<CHOICE Value="DE">Delaware</CHOICE>
<CHOICE Value="VA">Virginia</CHOICE>
<CHOICE Value="PA">Pennsylvania</CHOICE>
</CHOICES>

Well, you'd be wrong. In fact, as nearly as I can tell, the Value attrbiute of this element does nothing at all. It's not invalid if you use it; it doesn't break anything; it just doesn't do anything. And, the documentation leads you to believe that it should, which I think has the potential to cause a huge waste of time.

If you want a value that is different than the text, here's the right way to do it.

<CHOICES>
<CHOICE>MD#;Maryland</CHOICE>
<CHOICE>DE#;Delaware</CHOICE>
<CHOICE>VA#;Virginia</CHOICE>
<CHOICE>PA#;Pennsylvania</CHOICE>
</CHOICES>
<Default>MD</Default>

Originally posted as a blog-rant at http://thomascarpe.com/Lists/Posts/Post.aspx?ID=26. I'll update mine if you update yours. :-)

Value attribute not recognized by schema?
Setting the xmlns="http://schemas.microsoft.com/sharepoint/ for the List, the Value attribute is not recognized for the CHOICE element. Which is correct - the documentation or the schema?