Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
Reference
List Schema
A-F
 CHOICE Element

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
CHOICE Element (List)

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.

None

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.

Xml
<CHOICES>
  <CHOICE>Not Started</CHOICE>
  <CHOICE>In Progress</CHOICE>
  <CHOICE>Completed</CHOICE>
</CHOICES>
    
Community Content   What is Community Content?
Add new content RSS  Annotations
Value attribute not recognized by schema?      austegard   |   Edit   |   Show History
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?
Flag as ContentBug
This documentation is misleading...      Doc WattsMan   |   Edit   |   Show History

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 - a good idea but nothing more      Markus Buehler   |   Edit   |   Show History
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.

CAML Rendering and the Value attribute      Wouter van Vugt - Code Counsel   |   Edit   |   Show History
Funny thing is that the CAML rendering code for the Choice field does reference the Value attribute:

<ForEach Select="CHOICES/CHOICE">
...
<Property Select="Value"/>
...
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker