I am not able to add a new choice value to a SPFieldChoice column of a list. Here is my code
using (SPWeb myWeb = SPContext.Current.Web)
{
myWeb.AllowUnsafeUpdates = true;
SPList myList = myWeb.Lists["DemoList"]; //Gets a list named "MyList"
//Gets the field named "ChoiceField". Since ChoiceField is an SPFieldChoice I can cast it as
// such. SPFieldChoice also inherits SPField.
SPFieldChoice dropDown = (SPFieldChoice)myList.Fields["My Choice"];
//Add some values
dropDown.Choices.Add(txtNewChoice.Text);
dropDown.Update(); //Need to update the column for the changes to take affect
myList.Update();
myWeb.Update();
myWeb.AllowUnsafeUpdates = false;
foreach (var item in dropDown.Choices)
{
result.Text += item.ToString();
}
}
Please let me know if I missed any point. NOTE I am using a sandboxed solution to deploy the web part