我成功地创建了一个从SPFieldText继承的自定义字段,并且很高兴地将它作为控件呈现在输入表单上。
问题:
当使用()呈现字段时,我需要在querystring中创建一个带有ListitemID和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
}我用RenderPattern在fldtypes_Custom.xml中进行了实验,但在使用GetFieldValueAsHtml()呈现字段时,同样忽略了这一点;
我是不是天真地期待着一些不可能的事情?我愿意接受任何避免重写网络部分的方法.或者告诉我这件事做不到。
(现有的web部件呈现网格并调用GetFieldValueAsHtml()。我们知道我们可以改变web部件来实现这一点,但由于其他原因,这并不是一个理想的解决方案)。
发布于 2012-12-12 22:22:27
对于任何人偶然发现这一点,我证实,我的目标是不可能的。
我们被迫对web部件进行更改,以实现这种程度的定制。正如问题中所概述的,现有的web部件呈现网格并调用GetFieldValueAsHtml()。
发布于 2010-11-14 00:12:51
不确定这是否适用于SharePoint 2007,但使用SharePoint 2010,可以使用SPContext.Current.ListItem轻松获取当前显示的ListItem。
https://stackoverflow.com/questions/2624615
复制相似问题