是否可以在页面布局中设置 NumberField 的格式?
我正在开发一个 SharePoint 发布网站并设置其内容类型和页面布局。 我需要显示数字类型的年份字段的值。 目前的标记是:
<SharePointWebControls:NumberField FieldName="Year" runat="server" id="Year" />
默认行为的问题是它用逗号显示每个数字,例如“2,009”而不是“2009”。 有没有办法可以在字段上设置某种 String.Format 语法以使其正确显示?
我尝试创建一个新的渲染模板,如下所示:
<SharePoint:RenderingTemplate ID="YearNumberField" runat="server">
<Template>
<SharePoint:FormField ID="TextField" runat="server"/>
</Template>
</SharePoint:RenderingTemplate>
...但 FormField 对象上似乎没有任何“Format”属性。
谢谢你的帮助。
更新:
我尝试将 SharePoint:FormField 标记包装在 SharePoint:FormattedString 内。 不幸的是,该字段未格式化,结果与此问题相同。
I'm developing a SharePoint publishing site and setting up its content types and page layouts. I need to display the value for a Year field with type Number. The markup currently is:
<SharePointWebControls:NumberField FieldName="Year" runat="server" id="Year" />
The problem with the default behaviour is that it shows each number with a comma, e.g. "2,009" instead of "2009". Is there a way I can set some sort of String.Format syntax on the field to make it display correctly?
I tried creating a new rendering template which looks like this:
<SharePoint:RenderingTemplate ID="YearNumberField" runat="server">
<Template>
<SharePoint:FormField ID="TextField" runat="server"/>
</Template>
</SharePoint:RenderingTemplate>
... but there doesn't appear to be any 'Format' property on the FormField object.
Thanks for any help.
Update:
I tried wrapping the SharePoint:FormField tag inside SharePoint:FormattedString. Unfortunately the field was not formatted, same results as this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是渲染模板必须使用FormField。 这始终以以下格式呈现值:1,989 。 为了解决这个问题,需要捕获并更改渲染的文本以获得所需的输出。 以下是解决此问题的两种方法:
1. 编写继承自 NumberField 的自定义控件
可以重写 RenderFieldForDisplay 和 RenderFieldForInput 方法以提供所需的输出。 可以将附加属性添加到控件中以描述附加行为。
优点:无需更改渲染模板。
2. 编写在呈现模板中使用的自定义控件
(例如)使用正则表达式更改文本的控件可以环绕 FormField 控件。
优点:通用解决方案可用于任何类型的领域。
The issue is that the rendering template must use FormField. This always renders the value in the format: 1,989 . To resolve this the rendered text needs to be trapped and altered to get the desired output. Here are two approaches to resolving this:
1. Write a custom control inherited from NumberField
The RenderFieldForDisplay and RenderFieldForInput methods can be overridden to provide the desired output. Additional properties can be added to the control to describe additional behaviour.
Pros: No changes to rendering templates required.
2. Write a custom control for use in the rendering template
A control that (for example) uses regular expressions to alter text can wrap around the FormField control.
Pros: Generic solution can be used for any type of field.
来自另一个 SharePoint 博客
from Just Another SharePoint Blog