Sep 19, 2009

How to remove the value from the OOB choice type field in the column in list

Here the requirement is to add/remove value from the choice type field from the column created in list programmatically.

Here is the sample code for this..

-------------------------------------------------------------------

SPFieldChoice fieldName = (SPFieldChoice)ListName.Fields["ColumnName"];

//Check if the required choice value exist in the field

//If it exists then remove it from the choice collection

if (fieldName.Choices.Contains("ChoiceValue") == true)

{

fieldName.Choices.Remove(ChoiceValue);

fieldName.Update();

}

else

{

// Do nothing.Choice value does not exist

}

-------------------------------------------------

This way we can access any type of the column type provided by Sharepoint and add or remove the values programmatically

Your Job is done!!!

Enjoy!!!

No comments:

Post a Comment