Create multiple choice fields

To learn more about the different steps to create a custom field, read the For developers: Create custom fields for product types article.

Here is a list of the things that are specific for the multiple choice field:

  • Field CLR type: typeof(string).FullName
  • User friendly data type: UserFriendlyDataType.MultipleChoice
  • DB type: VARCHAR
  • Field type: typeof(ChoiceField).FullName

When creating a multiple choice field, where you create the field definition, you must also create the available choices for the field.

To do this perform the following:

  1. For each choice create an instance of the ChoiceItem class.
  2. Set the Text and Value properties of the instance.
  3. Add the items to a List of ChoiceItem.
  4. Serialize the list using a JavaScriptSerializer instance.
  5. Set the Choices property of the WcfFieldDefinition instance to the serialized value.

NOTE: When creating a multiple choice field, store your choices into an enumeration. The choices are not stored in the MetaField instance. The enumeration will help you work with the choices when setting or getting the value of the field via code.

Use the following code example:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Create yes/no fields