Get Values from Choice Field in SharePoint

Programmatically how to get the SharePoint Custom list/library choice values into dropdown list in SharePoint 2013.

  • In SharePoint mostly we used SharePoint custom list for retrieve the items from fields/columns.

  • Administrator or who has the access to the list/library can be add new items into SharePoint list Choice field like Year. Create a new web part to get the choice values programatically into Dropdown list.

  • This Articles I would like to show how to get the values from choice field from SharePoint custom list and display into dropdown list.Below are the steps to get it done.

  • Create new custom list/library and add new column name 'Year' with column type 'Choice'.

  • Here is the option to insert the values for dropdown list items – 'Type each choice on a separate line'.

Enter detail

And click on ok. Go to page to get the values into dd list. So this way you will get all the items into Drop down list programmatically.

Select year
Here is the code how to get choice values from SharePoint custom list/Library.

  1. private void BindYear()  
  2. {  
  3.    SPWeb _web = SPContext.Current.Web;  
  4.    SPList list = _web.Lists.TryGetList("Listtitle");  
  5.    SPFieldChoice YearChoice = (SPFieldChoice)list.Fields["FieldName"];  
  6.    for (int i = 0; i < YearChoice.Choices.Count; i++)  
  7.    {  
  8.       ddlYear.Items.Add(YearChoice.Choices[i].ToString());  
  9.    }  
  10. }  
I hope this will help SharePoint beginners to get the values from Choice field programmatically.

Ebook Download
View all
Learn
View all