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!!!

Advertisement

~ by Saurabh Mittal on September 19, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.