Create yes/no 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 yes/no choice field:

  • Field CLR type: typeof(bool).FullName
  • User friendly data type: UserFriendlyDataType.YesNo
  • DB type: BIT
  • Field type: typeof(ChoiceField).FullName

When creating a yes/no field you must also perform the following in:

  • Where you set the properties of the field definition, you must set additional property RenderChoiceAs. It gets or sets how the choices are rendered in the UI. Set this property to the following value: RenderChoicesAs.SingleCheckBox.
  • Where you create the field definition, you must also create a choice item that represents the yes/no question.
    To do this perform the following:
    1. Create an instance of the ChoiceItem class.
    2. Set the Text property of the instance to the question.
    3. Set the Value property of the instance to true.
    4. Add the item to a List of ChoiceItem.
    5. Serialize the list using a JavaScriptSerializer instance.
    6. Set the Choices property of the WcfFieldDefinition instance to the serialized value.

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?