Some USES of ASP.NET Eval evaluation operations

  • 2020-05-16 06:40:46
  • OfStack

< %# Bind("Subject") % > // bind field
< %# Container.DataItemIndex + 1% > // realize automatic numbering
< %# DataBinder.Eval(Container.DataItem, "[n]") % >
Commonly used methods (these 3 perform best)
< %# DataBinder.Eval(Container.DataItem, "ColumnName") % >
< %# DataBinder.Eval(Container.DataItem, "ColumnName", null) % >
< %# DataBinder.Eval(Container, "DataItem.ColumnName", null) % >
Other USES
< %# ((DataRowView)Container.DataItem)["ColumnName"] % >
< %# ((DataRowView)Container.DataItem).Row["ColumnName"] % >
< %# ((DataRowView)Container.DataItem)["adtitle"] % >
< %# ((DataRowView)Container.DataItem)[n] % >
< %# ((DbDataRecord)Container.DataItem)[0] % >
< %# (((custom type) Container.DataItem)). Property.ToString() % > // if the property is of string type, ToString() is not used
e.g
< %# DataBinder.Eval(Container.DataItem, "IntegerValue", "{0:c}") % >
The format string argument is optional. If the parameter is ignored, DataBinder.Eval returns the value of the object type,
// displays 2 decimal places
< %# DataBinder.Eval(Container.DataItem, "UnitPrice", "${0:F2}") % >
//{0:G} shows True or 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 >
// convert type
((string)DataBinder.Eval(Container, "DataItem.P_SHIP_TIME_SBM8")).Substring(4,4)
{0:d} date shows year, month and day only
{0: yyyy-mm-dd} displays the year, month and day in the format
{0:c} currency style
< % # Container. DataItem (" price ", "0.00} {0: $#, # #") % >
< %# 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} date shows year, month and day only
{0: yyyy-mm-dd
The style depends on the Settings in Web.config
{0: c} or {0: £0,000.00} currency style standard British currency style
< system.web >
< globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="en-US" / >
< /system.web >
It is shown as £3,000.10
{0: c} or string. Format (" {0: C} ", price); Chinese money style
< system.web >
< globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-cn" uiCulture="zh-cn" / >
< /system.web >
The display is ¥3,000.10
{0: c} or string. Format (" {0: C} ", price); American money style
< system.web >
< globalization requestEncoding="utf-8" responseEncoding="utf-8" / >
< /system.web >
The show is $3000.10

Related articles: