ASP.NET Eval 求值運(yùn)算的一些用法
<%# Container.DataItemIndex + 1%> //實(shí)現(xiàn)自動(dòng)編號(hào)
<%# DataBinder.Eval(Container.DataItem, "[n]") %>
通常使用的方法(這三個(gè)性能最好)
<%# 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 返回對(duì)象類型的值,
//顯示二位小數(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)英國(guó)貨幣樣式
<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); 中國(guó)貨幣樣式
<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); 美國(guó)貨幣樣式
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
顯示為 $3,000.10
- ASP.NET配置文件Web.config用法詳解
- ASP.net全局程序文件Global.asax用法分析
- ASP.NET中IsPostBack用法詳解
- ASP.NET Dictionary 的基本用法示例介紹
- 關(guān)于ASP.NET中TreeView用法的一個(gè)小例子
- 深入理解Asp.net中DataBinder.Eval的用法總結(jié)
- asp.net的IndexOf,LastIndexOf,IndexOfAny和LastIndexOfAny的用法
- asp.net中for和do循環(huán)語(yǔ)句用法分享
- TreeView 用法(有代碼)(asp.net)
- asp.net TIDFtp用法介紹
- asp.net Md5的用法小結(jié)
- ASP.NET中TimeSpan的用法實(shí)例解析
相關(guān)文章
asp.Net 中獲取一周第一天,一月第一天等實(shí)現(xiàn)代碼
.Net中獲取一周第一天、最后一天,一月第一天、最后一天2009-12-12
使用Supervisor守護(hù)ASP.NET?Core應(yīng)用程序進(jìn)程
這篇文章介紹了使用Supervisor守護(hù)ASP.NET?Core應(yīng)用程序進(jìn)程的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03
.NET中創(chuàng)建對(duì)象的幾種方式和對(duì)比
在 .net 中,創(chuàng)建一個(gè)對(duì)象最簡(jiǎn)單的方法是直接使用 new (), 在實(shí)際的項(xiàng)目中可能還會(huì)用到反射,本文就介紹了幾種創(chuàng)建方法,感興趣的可以了解一下2021-07-07
.NET 6開(kāi)發(fā)TodoList應(yīng)用引入數(shù)據(jù)存儲(chǔ)
這篇文章主要介紹了.NET 6開(kāi)發(fā)TodoList應(yīng)用引入數(shù)據(jù)存儲(chǔ),本篇文章僅完成了數(shù)據(jù)存儲(chǔ)服務(wù)的配置工作,目前還沒(méi)有添加任何實(shí)體對(duì)象和數(shù)據(jù)庫(kù)表定義,所以暫時(shí)沒(méi)有可視化的驗(yàn)證,僅我們可以運(yùn)行程序看我們的配置是否成功:下面來(lái)看詳細(xì)內(nèi)容吧2021-12-12
解析.netcore項(xiàng)目中IStartupFilter使用教程
netcore項(xiàng)目中有些服務(wù)是在通過(guò)中間件來(lái)通信的,比如orleans組件,今天通過(guò)實(shí)例代碼給大家介紹下netcore項(xiàng)目中IStartupFilter使用教程,感興趣的朋友一起看看吧2021-11-11
云服務(wù)器下搭建ASP.NET Core環(huán)境
本文給大家分享的是在云服務(wù)器上搭建ASP.NET Core環(huán)境以及成功運(yùn)行官網(wǎng)DEMO的教程,十分的細(xì)致全面,有需要的小伙伴可以參考下。2016-07-07
ASP.NET2.0中用Gridview控件操作數(shù)據(jù)的代碼
在ASP.NET 2.0中,加入了許多新的功能和控件,相比asp.net 1.0/1.1,在各方面都有了很大的提高2012-10-10
.NetCore使用過(guò)濾器實(shí)現(xiàn)登錄權(quán)限認(rèn)證的方法小結(jié)
這篇文章主要介紹了.NetCore使用過(guò)濾器實(shí)現(xiàn)登錄權(quán)限認(rèn)證幾種方式總結(jié),主要包括自定義行為過(guò)濾器在OnActionExecuting中實(shí)現(xiàn),自定義身份驗(yàn)證過(guò)濾器,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2022-06-06
asp.net訪問(wèn)Access數(shù)據(jù)庫(kù)溢出錯(cuò)誤
asp.net訪問(wèn)Access數(shù)據(jù)庫(kù)溢出錯(cuò)誤,大家會(huì)的幫忙解決下啊。2009-07-07

