[英]Format data with DataBinder.Eval
I need to convert the following line of code: 我需要转换以下代码行:
<%# DataBinder.Eval(Container.DataItem, "Id") %>
to 至
<%# DataBinder.Eval(Container.DataItem, "Id").ToString().PadLeft(3, '0') %>
The latter gives an exception of a malformed server tag. 后者提供了格式错误的服务器标记的例外。 How can I apply methods to the DataBinder output.
如何将方法应用于DataBinder输出。 Please note that I already know about the following but do not want to use it:
请注意我已经知道以下但不想使用它:
<%# DataBinder.Eval(Container.DataItem, "Id", "{FormatString}") %>
我遇到了同样的问题,这就是我所做的。
<%# DataBinder.Eval(Container.DataItem, "Id").ToString().PadLeft(3, Convert.ToChar("0")) %>
导致问题的原因是padding [padLeft(3,'0')]函数中存在单引号,无论如何都需要,并且在字符串的某些部分中存在双引号...是否可以移动格式代码隐藏 - 使用数据绑定事件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.