I have a ReleaseMonth column in my custom list. currently set to single line of text.

i have requiremnet to shows a dropdown list that includes next three months and year.

For example :- if the current month is April 2013, then the column should be populated with list of May 2013, Jun 2013, Jul 2013.

the default would be blank. user shoud select choice and save. during edit of form, the column should display previous data store in column and after user clicks then give choice for next 3 month data.

pls help me.

have read and tried the below similar link from same blog: Showing only last six months in a dropdown


Attaching an event receiver to your list which dynamically populates the values in your ReleaseMonth column (as recommend by @Alex Choroshin) would be a good start, but you're probably going to run into problems when you try also display the value of the originally selected value.

This is because the values in the SPFieldChoice column are actually displayed for every item in the list, and your list items will probably each need to display a different set of options / values -- because each item would potentially have been entered with a different ReleaseMonth value.

So my recommendation would be to do the following:

Step 1:

Attach a list item event reciever to your list, but instead of doing any filtering inside it, simply populate it with a range of date values, starting from the minimum possible ReleaseMonth value (if your system defines one, or if not, then just the value of the oldest selected ReleaseMonth value), through to the current month and it's two successive months.

This will atleast allow your list's display form to pull the appropriate value from the column for every and any list item. So far so good, now to take care of the field in edit mode...

Step 2:

Then, use either SharePoint Designer or a feature reciver, add some JavaScript to your list's edit form which dynamically hides the date values which don't apply to the that specific item.

To do this, merely loop through every item in the choice field's dropdown and hide every value that does not equal the originally selected value, the current month, or any month in the future.

Note: The event receiver should be set to fire on the ItemAdded, ItemUpdated and ItemDeleted events to ensure that the values in the ReleaseMonth field are automatically re-evaluated and repopulated automatically every time the acceptable range of date values is changed.

  • currently im new babiee to SP development task and know very little like adding jquery etc. can you pls quide me or send me the code and steps to do in my list. TIA.
    – Deepak
    Apr 10 '13 at 8:46
  • In SharePoint Designer, browse to your list. In the "Forms" pane, right-click "EditForm.aspx" and select "Edit File in Advanced Mode". From here, you can write your JavaScript / jQuery function directly in the "PlaceHolderAdditionalPageHead" content placeholder. Alternatively, navigate to your list's edit form in the browser, then append "?toolpaneview=2" to the end of the URL and hit enter -- this will open the form in edit mode. From here, simply drop a content editor web part into the page and place your script in that. Apr 29 '13 at 8:55

I would suggest using event receiver that fires on item adding/item updating event and will populate the choice field dynamically based on the current date.

  • Will that really work in this scenario? Concerned that the user will never get to choose a value. Apr 10 '13 at 7:48
  • I'm also concerned that this wouldn't satisfy the requirement to also show each item's originally / currently selected ReleaseMonth value? I've proposed an alternative solution which would solve this, so feel free to chime in. Apr 10 '13 at 8:19
  • can this be done through SP designer or Jquery. can you pls send me link or tutorail for using event receiver and code for the same.
    – Deepak
    Apr 10 '13 at 8:49
  • Here's a nice tutorial learningsharepoint.com/2010/06/27/… Apr 10 '13 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.