ASP.NET Eval 求值运算的一些用法

318人浏览 / 0人评论
//绑定字段
//实现自动编号

通常使用的方法(这三个性能最好)



其他用法





//如果属性为字符串类型就不用ToString()了
DataBinder.Eval用法范例

格式化字符串参数是可选的。如果忽略参数,DataBinder.Eval 返回对象类型的值,
//显示二位小数

//{0:G}代表显示True或False

AlternateText=''
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Discontinued", "~/images/{0:G}.gif") %>' />

//转换类型
((string)DataBinder.Eval(Container, "DataItem.P_SHIP_TIME_SBM8")).Substring(4,4)
{0:d} 日期只显示年月日
{0:yyyy-mm-dd} 按格式显示年月日
{0:c} 货币样式


Specifier Type Format Output (Passed Double 1.42) Output (Passed Int -12400)
c Currency {0:c} $1.42 -$12,400
d Decimal {0:d} System.FormatException -12400
e Scientific {0:e} 1.420000e+000 -1.240000e+004
f Fixed point {0:f} 1.42 -12400.00
g General {0:g} 1.42 -12400
n Number with commas for thousands {0:n} 1.42 -12,400
r Round trippable {0:r} 1.42 System.FormatException
x Hexadecimal {0:x4} System.FormatException cf90
{0:d} 日期只显示年月日
{0:yyyy-mm-dd} 按格式显示年月日
样式取决于 Web.config 中的设置
{0:c} 或 {0:£0,000.00} 货币样式 标准英国货币样式



显示为 £3,000.10
{0:c} 或 string.Format("{0:C}", price); 中国货币样式



显示为 ¥3,000.10
{0:c} 或 string.Format("{0:C}", price); 美国货币样式



显示为 $3,000.10

全部评论

晴天下起了小雨
2017-10-01 18:00
很喜欢,果断关注了
wjmyly7336064
2017-10-01 18:00
相当实用,赞美了
橘大佬
2017-10-01 18:00
就是有些细节再到位点就好了…