我已经成功创建了一个继承自SPFieldText的自定义字段,并且很高兴完全控制在输入表单上将其呈现为控件。
在使用GetFieldValueAsHtml()渲染字段时,我需要使用查询字符串 中的 ListId和ListitemID创建指向弹出窗口的链接。
这样的事情:
public class CustomField : SPFieldText
{
public CustomField (SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
{
}
public CustomField (SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName)
{
}
public override string GetFieldValueAsHtml(object value)
{
return string.Format(
"javascript:window.open('{0}/_layouts/Popup.aspx?ListId={1}&ItemId={2}','Popup','status=0,scrollbars=0,titlebar=0,resizable=1,toolbar=0,location=0,width=600,height=500');return false;",
SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'),
LISTID, LISTITEM.ID
);
}
显然,SPContext没有对列表或项目的引用,并且没有任何属性似乎公开当前项目。我尝试在控件中重载属性,但在渲染字段时似乎没有调用这些属性。
// None of these properties are invoked when rendering the field as above
public class CustomFieldControl : TextField
{
public override object ItemFieldValue
public override object ListItemFieldValue
public override string Text
public override object Value
}
我已经在fldtypes_Custom.xml中尝试了RenderPattern但是在使用GetFieldValueAsHtml()渲染字段时也会忽略它;
我天真地期待一些不可能的东西吗? 我对任何避免重写网页部分的方法持开放态度......或者只是告诉我它无法完成。
(现有的Web部件呈现网格并调用GetFieldValueAsHtml()。我们知道我们可以更改Web部件来实现此目的,但由于其他原因,这不是理想的解决方案。)
答案 0 :(得分:0)
不确定这是否适用于SharePoint 2007,但使用SharePoint 2010,可以使用SPContext.Current.ListItem轻松获取当前正在显示的ListItem。
答案 1 :(得分:0)
对于任何磕磕绊绊的人,我确认我的目标是不可能的。
我们被迫在Web部分进行更改以实现此级别的自定义。如问题中所述,现有Web部件呈现网格并调用GetFieldValueAsHtml()。