SharePoint 2003: Setting MultiChoice Fields Programmatically

When using a choice field in SharePoint 2003, you may want to allow multiple values to be selected via checkboxes. When doing so, the field becomes type MultiChoice behind the scenes (different to a Choice type). To set assign multiple choice values to a multichoice field programmatically you need to separate different choice instances with a semicolon then hash (as well as at the start and end of the string). Note I worked this out by looking in the UserData table for my site collection.

currentList = new SPSite("mysiteurl").OpenWeb().Lists["MyList"];
SPListItem listItem = currentList.Items.Add();
listItem["nameOfAMultiChoiceField"] = ";#red;#green;#blue;# ";

SharePoint 2003: How choice / lookup options are populated

In SharePoint 2003, the way fields are rendered is determined by RenderPatterns in the FLDTYPES.XML file. Render patterns are xml specifications for how a field should be rendered. Most field types (e.g. text, dates etc) don’t need to be pre-populated with any information, however some do, such as a choice field or lookup field. Below are some rough notes on how options are populated:

Choice values are populated in a choice control by the ows.js file (fields.xml defines where values for the select options are to be passed through). These are actually rendered at runtime using JavaScript (surprisingly).

Lookup options appear to be populated via the SelectOptions element in the renderpattern. From what Ive looked into, it appears that you cannot manipulate SelectOptions (e.g. there are no attributes for filtering etc). See

Due to the nature of the renderpatterns, it looks like you cannot construct your own options via a CAML queries (i.e. when creating a custom field type, or altering an existing field type). There are certainly no examples of this in FLDTYPES.XML. Even if you could, I am not sure how you would get the results of the CAML query into an array an iterate over it. I guess its not possible.

The only way around this that I can think of is to use JavaScript to clear and then repopulate the options of a select box (maybe obtaining the new options via an ajax webservices call).