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.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. 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?