asp.net中databinder.eval用法的总结
<%# bind("subject") %> //綁定字段
<%# container.dataitemindex + 1%> //實(shí)現(xiàn)自動編號
<%# databinder.eval(container.dataitem, "[n]") %>
通常使用的方法(這三個性能最好)
<%# databinder.eval(container.dataitem, "columnname") %>
<%# databinder.eval(container.dataitem, "columnname", null) %>
<%# databinder.eval(container, "dataitem.columnname", null) %>
其他用法
<%# ((datarowview)container.dataitem)["columnname"] %>
<%# ((datarowview)container.dataitem).row["columnname"] %>
<%# ((datarowview)container.dataitem)["adtitle"] %>
<%# ((datarowview)container.dataitem)[n] %>
<%# ((dbdatarecord)container.dataitem)[0] %>
<%# (((自定義類型)container.dataitem)).屬性.tostring() %>//如果屬性為字符串類型就不用tostring()了
databinder.eval用法范例
<%# databinder.eval(container.dataitem, "integervalue", "{0:c}") %>
格式化字符串參數(shù)是可選的。如果忽略參數(shù),databinder.eval 返回對象類型的值,
//顯示二位小數(shù)
<%# databinder.eval(container.dataitem, "unitprice", "${0:f2}") %>
//{0:g}代表顯示true或false
<itemtemplate>
<asp:image width="12" height="12" border="0" runat="server"
alternatetext='<%# databinder.eval(container.dataitem, "discontinued", "{0:g}") %>'
imageurl='<%# databinder.eval(container.dataitem, "discontinued", "~/images/{0:g}.gif") %>' />
</itemtemplate>
//轉(zhuǎn)換類型
((string)databinder.eval(container, "dataitem.p_ship_time_sbm8")).substring(4,4)
{0:d} 日期只顯示年月日
{0:yyyy-mm-dd} 按格式顯示年月日
{0:c} 貨幣樣式
<%#container.dataitem("price","{0:¥#,##0.00}")%>
<%# databinder.eval(container.dataitem,"company_ureg_date","{0:yyyy-m-d}")%>
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 中的設(shè)置
{0:c}?? 或 {0:£0,000.00} 貨幣樣式?? 標(biāo)準(zhǔn)英國貨幣樣式
<system.web>
<globalization requestencoding="utf-8" responseencoding="utf-8" culture="en-us" uiculture="en-us" />
</system.web>
顯示為 £3,000.10
{0:c}?? 或 string.format("{0:c}", price); 中國貨幣樣式
<system.web>
<globalization requestencoding="utf-8" responseencoding="utf-8" culture="zh-cn" uiculture="zh-cn" />
</system.web>
顯示為 ¥3,000.10
{0:c}?? 或 string.format("{0:c}", price); 美國貨幣樣式
<system.web>
<globalization requestencoding="utf-8" responseencoding="utf-8" />
</system.web>
顯示為 $3,000.10
轉(zhuǎn)載于:https://www.cnblogs.com/bnq4ever/archive/2009/02/23/1396851.html
總結(jié)
以上是生活随笔為你收集整理的asp.net中databinder.eval用法的总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【资源分享】Windows XP SP1
- 下一篇: 罗永浩锤子ROM Pre-α公测版下载及