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;# ";

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>