Question

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):

ASPX:

<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! =)

Was it helpful?

Solution

Alex,

You should set the control as follow:

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

Where 1 is for true, and 0 is for false

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top