我正在尝试在我的自定义newform上设置Booleanfield的价值。 如果我尝试从Codebehind做到这一点,视觉上它不会改变,但是当项目将保存时,此字段将为空(既不为真,也不是假):

aspx:

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

aspx.cs (在onload方法中调用):

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

我甚至试图设置.aspx(得到“解析器错误消息”):

<SharePoint:BooleanField runat="server" FieldName="boolField" ControlMode="New" ID="MyCustomField" Value="TRUE"/>
. 但是,如果我会尝试更改任何其他类型的字段(例如,numberfield),一切都会好的。

我在哪里错了,我如何从CodeBehind(或至少在aspx中)进行?

提前感谢!=)

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
scroll top