Retrieve a SharePoint Choice Field Value Using Server Object Model C#

In this hint, I will explain How to

Retrieve a SharePoint Choice Field Value using C# Server Object Model.


Steps:

  • Open your SharePoint Solution.
  • Add the following bind() function in your code.
  • Call bind() function in Load with no postback.

Retrieve SharePoint Choice Field Value to a drop-down list using C#

private void bind()
   {
      SPWeb site = SPContext.Current.Web;
      SPList list = site.Lists["ListName"];
      SPFieldChoice myChoicesfield = (SPFieldChoice)list.Fields["FieldName"];
        for (int i = 0; i < myChoicesfield.Choices.Count; i++)
          {
            DropDownListName.Items.Add(myChoicesfield.Choices[i].ToString());
          }
   }

Retrieve SharePoint Choice Field Value to a checkbox list using C#


  private void bind()
     {
         SPWeb site = SPContext.Current.Web;
         SPList list = site.Lists["ListName"];
         SPFieldMultiChoice choices = (SPFieldMultiChoice)list.Fields[FieldName];
          foreach (string str in choices.Choices)
            {
                cblCheckboxList.Items.Add(new ListItem(str, str));
            }
      }

See also
Advertisements

Get and Set a SharePoint URL Field Value Using Server Object Model C#

At this hint, I explains How to Get and Set a SharePoint URL Field value using Server Object Model C#

To set a SharePoint URL Field value Continue reading Get and Set a SharePoint URL Field Value Using Server Object Model C#

Get and Set a SharePoint Multiple Choice Field Value Using Server Object Model C#

At this hint, I explains How to Get and Set a SharePoint Multiple Choice Field value using Server Object Model C#

To set a SharePoint Multiple Choice Field value Continue reading Get and Set a SharePoint Multiple Choice Field Value Using Server Object Model C#