Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to add choices programmatically to an SPFieldChoice so that its select box has values with Current Year - 5 to Current Year + 5.

What is the best way to do this?

Ex:

2005
2006
2007
...
2010 -- current year
...
2013
2014
2015
share|improve this question

1 Answer 1

Where "spfc" is an object of type SPFieldChoice:

int year = DateTime.Now.Year - 5;
for (int i = 0; i < 10; i++)
{
    spfc.Choices.Add((year + i).ToString());
}
spfc.Update();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.