是否可以在页面布局中设置 NumberField 的格式?

发布于 2024-07-16 16:14:10 字数 831 浏览 11 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无戏配角 2024-07-23 16:14:10

问题是渲染模板必须使用FormField。 这始终以以下格式呈现值:1,989 。 为了解决这个问题,需要捕获并更改渲染的文本以获得所需的输出。 以下是解决此问题的两种方法:

1. 编写继承自 NumberField 的自定义控件

可以重写 RenderFieldForDisplay 和 RenderFieldForInput 方法以提供所需的输出。 可以将附加属性添加到控件中以描述附加行为。

优点:无需更改渲染模板。

2. 编写在呈现模板中使用的自定义控件

(例如)使用正则表达式更改文本的控件可以环绕 FormField 控件。

<SharePoint:RenderingTemplate ID="YearField" runat="server">
    <Template>
        <RX:RegexManipulatorControl runat="server"
                Mode="Replace"
                Expression=","
                Replacement="">
            <SharePoint:FormField runat="server"/>
        </RX:RegexManipulatorControl>
    </Template>
</SharePoint:RenderingTemplate>

优点:通用解决方案可用于任何类型的领域。

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.

<SharePoint:RenderingTemplate ID="YearField" runat="server">
    <Template>
        <RX:RegexManipulatorControl runat="server"
                Mode="Replace"
                Expression=","
                Replacement="">
            <SharePoint:FormField runat="server"/>
        </RX:RegexManipulatorControl>
    </Template>
</SharePoint:RenderingTemplate>

Pros: Generic solution can be used for any type of field.

孤寂小茶 2024-07-23 16:14:10

来自另一个 SharePoint 博客

在 SharePoint 中打开列表视图
设计师。

右键单击数据视图 Web 部件。
(名单)

选择转换为 XSLT 数据视图

点击您想要的数字字段
喜欢格式化

A> 将出现显示数据字段,
格式为

单击下面的链接“格式为”-
数字格式选项

在“选项”下取消选择“使用 1000”
分隔符

点击“确定”

保存更改并按 F12
预览

from Just Another SharePoint Blog

Open the list view in SharePoint
Designer.

Right click on the data view web part.
(the list)

Select Convert to XSLT Data View

Click on the number field you would
like to format

A > will appear showing Data Field,
Format As

Click on the link below Format As -
Number formatting options

Under Options deselect Use 1000
separator

Click OK

Save your changes and hit F12 to
preview

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文