Thursday, May 29, 2008

Programmatically adding data to SharePoint List’s Choice column

SharePoint has a column type called “CHOICE”. This column will be useful for presenting one of the field from the following
  • Dropdown List
  • Radio Buttons
  • Check Boxes (To Select Multiple Items)

Consider I’ve a list “Resource List” with following columns

Column Name ------ Type
Resource Name --> Single Line of Text
Languages Known --> Choice (C#, VB.NET, Java, C, C++) – Multiselect

Languages Known” is the CHOICE field (Check Boxes), to select multiple languages known by the resource.When adding new items to the Resouce List, notice that multiple items selected for the ‘Languages Known’ CHOICE column will be seperated by semi colan(‘;’).



I had a requirement to add the list item by code. I have used “ChoiceA;ChoiceB;..ChoiceN” for storing the ListItem’s multi-select CHOICE field. After adding ListItem by code, I have Edited the newly added item in the browser, but no check box has been selected for the item which was added by code.

Then after a little effort I found that the multi-select CHOICE data is stored as “;#ChoiceA;#ChoiceB;#...;#
See the below code for adding listitem to Resource List.


Below screen shows the newly added Item in the edit mode