I'm trying to set value for BooleanField on my custom NewForm. If I try to do it from codebehind, visually it doesn't change, but when the item will be saved this field will be empty (neither true nor false):


<SharePoint:BooleanField runat="server" FieldName="boolField" ControlMode="New" ID="MyCustomField"/>

ASPX.CS (invokes in OnLoad method):

if (!SPContext.Current.Web.CurrentUser.IsSiteAdmin) // For example
    MyCustomField.Value = true; // Visually no changes
    MyCustomField.UpdateFieldValueInItem(); // Still nothing

I even tried to set in .aspx (and got "Parser error message"):

<SharePoint:BooleanField runat="server" FieldName="boolField" ControlMode="New" ID="MyCustomField" Value="TRUE"/>

However, if I'll try to change Field of any other type (NumberField, for example), everything will be OK.

Where am I wrong, and how can I do it from codebehind (or at least in aspx)?

Thanks in advance! =)



You should set the control as follow:

MyCustomField.ItemFieldValue = "1";
MyCustomField.Field.DefaultValue = "1";

Where 1 is for true, and 0 is for false

  • Tried this. Unfortunately, I get InvalidCastException. Also, I have no "DefaulView" property... – Alex Apr 2 '14 at 13:00
  • DefaultValue it is.. – Arsalan Adam Khatri Apr 2 '14 at 13:03
  • Sorry, I meant I have no DefaultValue property! (just a typo). – Alex Apr 2 '14 at 13:21
  • Yeah! I should be using it like this: MyCustomField.ItemFieldValue = "1"; MyCustomField.Field.DefaultValue = "1"; – Alex Apr 2 '14 at 13:52
  • Does that work ? – Arsalan Adam Khatri Apr 2 '14 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.