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:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?