DataBinder所有用法

2022-03-08 10:52:27 字數 4152 閱讀 7240

-------databinder所有用法------------------

<%

# bind(

"subject") 

%>

//繫結字段

<%

# container.dataitemindex +1

%>

//實現自動編號

<%

# 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", 

"") %>

格式化字串引數是可選的。如果忽略引數,databinder.eval 返回物件型別的值,

//顯示二位小數

<%

# databinder.eval(container.dataitem, 

"unitprice", 

"$") 

%>

//代表顯示true或false

<

itemtemplate

>

<

asp:image 

width

="12"

height

="12"

border

="0"

runat

="server"

alternatetext

='<%# 

databinder.eval(container.dataitem, "discontinued", "") %

>

'imageurl='

<%

# databinder.eval(container.dataitem, 

"discontinued", 

"~/images/.gif") 

%>

' />

itemtemplate

>

//轉換型別

((string)databinder.eval(container, "dataitem.p_ship_time_sbm8")).substring(4,4)

日期只顯示年月日

按格式顯示年月日

貨幣樣式

<%

#container.dataitem(

"price",

"")%>

<%

# databinder.eval(container.dataitem,

"company_ureg_date",

"")%>

specifier type     format   output (passed double 1.42)  output (passed int -12400) 

c  currency             $1.42     -$12,400 

d  decimal             system.formatexception  -12400 

e  scientific          1.420000e+000    -1.240000e+004 

f  fixed point       1.42    -12400.00 

g  general           1.42     -12400 

n  number with commas for thousands    1.42     -12,400 

r  round trippable      1.42     system.formatexception 

x  hexadecimal      system.formatexception   cf90 

日期只顯示年月日

按格式顯示年月日

樣式取決於 web.config 中的設定

或  貨幣樣式  標準英國貨幣樣式

<

system

.web

>

<

globalization 

requestencoding

="utf-8"

responseencoding

="utf-8"

culture

="en-us"

uiculture

="en-us"

/>

system.web

>

顯示為 £3,000.10

或 string.format("", price); 中國貨幣樣式

<

system

.web

>

<

globalization 

requestencoding

="utf-8"

responseencoding

="utf-8"

culture

="zh-cn"

uiculture

="zh-cn"

/>

system.web

>

顯示為 ¥3,000.10

或 string.format("", price); 美國貨幣樣式

<

system

.web

>

<

globalization 

requestencoding

="utf-8"

responseencoding

="utf-8"

/>

system.web

>

顯示為 $3,000.10

databinder.eval(container.dataitem,"name")和container.dataitem("name")有什麼區別?

databinder 是system.web裡面的乙個靜態類,它提供了eval方法用於簡化資料繫結表示式的編寫,但是它使用的方式是通過reflection等開銷比較大 的方法來達到易用性,因此其效能並不是最好的。而container則根本不是任何乙個靜態的物件或方法,它是asp.net頁面編譯器在資料繫結事件處 理程式內部宣告的區域性變數,其型別是可以進行資料繫結的控制項的資料容器型別(如在repeater內部的資料繫結容器叫repeateritem),在這 些容器類中基本都有dataitem屬性,因此你可以寫container.dataitem,這個屬性返回的是你正在被繫結的資料來源中的那個資料項。如 果你的資料來源是datatable,則這個資料項的型別實際是datarowview。

反射的所有用法

1.載入類的三種方式 view plain 載入類方法1 string classname cn.itcast.bean.person class clazz1 class forname classname 獲取類的位元組碼拿到類 載入類方法2 class clazz2 person class ...

setiosflags所有用法總結

setiosflags的引數是該流的格式標誌值,這個值由如下位掩碼 ios列舉器 指定,並可用位或or 運算子進行組合 ios skipws 在輸人中跳過空白。ios left 左對齊值,用填充字元填充右邊。ios right 右對齊值 用填充字元填充左邊 預設對齊方式 ios internal 在...

反射的所有用法

1.載入類的三種方式 載入類方法1 string classname cn.itcast.bean.person class clazz1 class.forname classname 獲取類的位元組碼拿到類 載入類方法2 class clazz2 person.class 在框架中用的不多 載入...