深入理解Asp.net中DataBinder.Eval的用法總結(jié)
<%# 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
- Android進(jìn)程間通信(IPC)機(jī)制Binder簡要介紹
- 理解Android系統(tǒng)Binder機(jī)制
- asp.net MVC利用自定義ModelBinder過濾關(guān)鍵字的方法(附demo源碼下載)
- Android4.1中BinderService用法實(shí)例分析
- 淺析DataBinder.Eval和Eval的區(qū)別
- android IPC之binder通信機(jī)制
- 使用jQuery向asp.net Mvc傳遞復(fù)雜json數(shù)據(jù)-ModelBinder篇
- 一個用xslt樣式將xml解析為xhtml的類TransformBinder(兼容FF和IE7.0)
- Android深入淺出之Binder機(jī)制
相關(guān)文章
Repeater全選刪除和分頁實(shí)現(xiàn)思路及代碼
Repeater控件想必熟悉.net web開發(fā)的人員是很了解不過的了,接下來將與大家共同學(xué)習(xí)下它的全選刪除和分頁,感興趣的你可不要錯過了哈,希望可以幫助到你2013-03-03
Asp.net使用HttpModule壓縮并刪除空白Html請求的實(shí)現(xiàn)代碼
當(dāng)我們壓縮我的Response后再傳到Client端時,可以明顯節(jié)省寬帶. 提升Site的性能. 現(xiàn)在的瀏覽器大部分都支持Gzip,Deflate壓縮2011-11-11
.Net中的Http請求調(diào)用詳解(Post與Get)
在我們服務(wù)端調(diào)用第三方接口時,如:支付寶,微信支付,我們服務(wù)端需要模擬http請求,下面這篇文章主要給大家介紹了關(guān)于.Net中Http請求調(diào)用(Post與Get)的相關(guān)資料,需要的朋友可以參考下2022-09-09
ASP.NET Core依賴注入系列教程之控制反轉(zhuǎn)(IoC)
這篇文章主要給大家介紹了關(guān)于ASP.NET Core依賴注入系列教程之控制反轉(zhuǎn)(IoC)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11
IIS故障(Connections_Refused)問題分析及處理
這幾天某地市Web服務(wù)器連續(xù)多次出現(xiàn)故障問題(Connections_Refused),正好借這個案例向大家詳細(xì)介紹下,需要了解的朋友可以參考下2012-12-12
ASP.NET Core MVC通過IViewLocationExpander擴(kuò)展視圖搜索路徑的實(shí)現(xiàn)
這篇文章主要介紹了ASP.NET Core MVC通過IViewLocationExpander擴(kuò)展視圖搜索路徑的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04

