为什么这个布尔字符串格式不起作用?

发布于 2024-10-04 00:51:46 字数 495 浏览 0 评论 0原文

我目前有以下 GridView TemplateField

<asp:TemplateField HeaderText="Despatched">
    <ItemTemplate><%# IIf(Eval("Despatched"), "Yes", "No")%></ItemTemplate>
</asp:TemplateField>

这工作正常,但我读过我可以执行以下操作,我认为这更简洁:

<asp:BoundField HeaderText="Despatched" DataField="Despatched" DataFormatString="{0:Yes;No}" />

但是,这仍然返回 True/False 值而不是 Yes/No

为什么这不起作用?

谢谢。

I currently have the following GridView TemplateField:

<asp:TemplateField HeaderText="Despatched">
    <ItemTemplate><%# IIf(Eval("Despatched"), "Yes", "No")%></ItemTemplate>
</asp:TemplateField>

This works fine, but I've read I can do the following instead, which I think is a lot neater:

<asp:BoundField HeaderText="Despatched" DataField="Despatched" DataFormatString="{0:Yes;No}" />

However, this still returns True/False values instead of Yes/No

Why isn't this working?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

你是我的挚爱i 2024-10-11 00:51:46

AFAIK,bool.ToString() 不支持自定义格式化字符串,例如 {0:Yes;No},尽管我确实承认这是一个好主意:-)

以下代码:

    bool b = true;
    Console.WriteLine("{0:Yes;No}", b);

无论 .NET 框架版本如何,始终显示 True (2 、 3、 4) 您使用。

AFAIK, bool.ToString() does not support a custom formatting string such as {0:Yes;No} although I truly admit it would be a good idea :-)

The following code:

    bool b = true;
    Console.WriteLine("{0:Yes;No}", b);

Always display True whatever .NET framework version (2, 3, 4) you use.

终止放荡 2024-10-11 00:51:46

您应该使用 DateFormatString 将 HtmlEncode="false" 添加到 BoundField:

<asp:BoundField HeaderText="Despatched" DataField="Despatched" DataFormatString="{0:Yes;No}" HtmlEncode="false" />

http://weblogs.asp.net/rajbk/archive/2005/10/31/boundfield-dataformatstring-attribute-not-being-applied.aspx< /a>

You should add HtmlEncode="false" to your BoundField with DateFormatString:

<asp:BoundField HeaderText="Despatched" DataField="Despatched" DataFormatString="{0:Yes;No}" HtmlEncode="false" />

http://weblogs.asp.net/rajbk/archive/2005/10/31/boundfield-dataformatstring-attribute-not-being-applied.aspx

似最初 2024-10-11 00:51:46

您拥有的代码是准确的。您可以尝试清理并重新编译网站,看看行为是否发生变化。如果这是来自部署,请在复制新文件之前删除目标。

我只是感觉 Visual Studio 没有更新部署中的 .aspx 文件。我发现这种情况发生得太频繁了。

The code you have is accurate. You might try cleaning and recompiling the site to see if the behavior changes. If this is from a deployment, delete the destination before copying the new files out.

I just get the feeling that visual studio didn't update your .aspx file on a deployment. Which I've found tends to happen a little too frequently.

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