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

At this hint, I explains How to retrieve a SharePoint Choice Field Value using Server Object Model C# and store it in a DropDownList or CheckBoxList by following the mentioned steps below :

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

In case of using DropDownList

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());
          }
   }

In case of using CheckBoxList

  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));
            }
      }

Enjoy 🙂

See also

Advertisements

One thought on “Retrieve a SharePoint Choice Field Value Using Server Object Model C#

  1. Everyone seems to have been sent from a Twitter for iphone app development that these companies can deliver tools to
    their prospective customers so that they can once
    again rule over the technological world.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s