为什么这个布尔字符串格式不起作用?
我目前有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AFAIK,bool.ToString() 不支持自定义格式化字符串,例如 {0:Yes;No},尽管我确实承认这是一个好主意:-)
以下代码:
无论 .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:
Always display True whatever .NET framework version (2, 3, 4) you use.
您应该使用 DateFormatString 将
HtmlEncode="false"
添加到 BoundField: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:http://weblogs.asp.net/rajbk/archive/2005/10/31/boundfield-dataformatstring-attribute-not-being-applied.aspx
您拥有的代码是准确的。您可以尝试清理并重新编译网站,看看行为是否发生变化。如果这是来自部署,请在复制新文件之前删除目标。
我只是感觉 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.