Adding a boolean field to the backend section

Posted by Community Admin on 05-Aug-2018 12:51

Adding a boolean field to the backend section

All Replies

Posted by Community Admin on 20-Dec-2011 00:00

Hi all,

I'm trying to add a field to my backend main section that should represent a checkbox (boolean field).

This is my definition:

var authorizeField = new ChoiceFieldElement(paymentSection)
    ID = "authorizeFieldControl",
    DataFieldName = "Authorize",
    FieldType = typeof(ChoiceField),
    RenderChoiceAs = RenderChoicesAs.SingleCheckBox,
    DisplayMode = displayMode,
    MutuallyExclusive = true,
    CssClass = "sfCheckBox",
    Title = (displayMode == FieldDisplayMode.Read) ? "Active?" : string.Empty,
    WrapperTag = HtmlTextWriterTag.Li,
    ResourceClassId = typeof(DonationsResources).Name,
;
ChoiceElement item = new ChoiceElement(authorizeField.ChoicesConfig)
    Text = "Active?"
;
 
authorizeField.ChoicesConfig.Add(item);

I'm getting this error:
Unable to cast object of type 'Telerik.Sitefinity.Web.UI.ContentUI.Config.ContentViewSectionElement' to type 'Telerik.Sitefinity.Web.UI.Fields.Config.FieldDefinitionElement'.

What am I doing wrong?

Regards,
Daniel

Posted by Community Admin on 22-Dec-2011 00:00

Hi Daniel,

I think the error you are getting is not related to this code. The code is fine, but probably the element, to which you add this ChoiceFieldElement is not the correct type. Can you provide more information from the stack trace or code for the rest of the fields that you add to the main section?

All the best,
Slavo
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

This thread is closed