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

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s