+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Adding a boolean field to the backend section

Adding a boolean field to the backend section

2 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    20 Dec 2011
    Link to this post
    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
  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    22 Dec 2011
    Link to this post
    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 >>

2 posts, 0 answered