将SharePoint BaseFieldControl BooleanField设置为true

时间:2014-09-01 09:43:31

标签: c# sharepoint sharepoint-2010 sharepoint-2013

我正在使用复选框控件创建自定义SharePoint 2013编辑表单。我正在使用SharePoint BaseFieldControl对象。

 BaseFieldControl webControl = field.FieldRenderingControl;
 webControl.ID = string.Format("ctrl_{0}",field.InternalName);
 webControl.FieldName = field.Title;this.Controls.Add(webControl);
 webControl.ControlMode = SPControlMode.edit;

 SPQuery camlQuery = new SPQuery();                
 camlQuery.ViewXml = String.Format("<View><Query><Where><Geq><FieldRef Name='ID'/>" +
 <Type='Number'>{0}</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>", id);

 SPListItemCollection items = SafeguardingList.GetItems(camlQuery);               
 SPListItem item = items[0];

 if (items.Count > 0 && !string.IsNullOrEmpty(item[field.Title].ToString()))
 {                    
  SPFieldType fieldType = field.Type;
  switch (fieldType)
  {
    case SPFieldType.Boolean:
    this.Controls.Add(webControl);
    break;
  }
}

我正在尝试在呈现页面时将复选框控件设置为“True”。

<input name="name$ctl00$BooleanField" id="name_ctl00_BooleanField" type="checkbox"/>

我试过了:

webControl.ItemFieldValue =“1”;

webControl.Field.DefaultValue =“1”;

这似乎不起作用。

先谢谢...

0 个答案:

没有答案