Summary of DataBinder. Eval usage in Asp.net
<% # Bind ("Subject") %> // Bind a field
<% # Container. DataItemIndex + 1%> // implement automatic numbering
<% # DataBinder. Eval (Container. DataItem, "[n]") %>
Common method (the best performance of these three methods)
<% # DataBinder. Eval (Container. DataItem, "ColumnName") %>
<% # DataBinder. Eval (Container. DataItem, "ColumnName", null) %>
<% # DataBinder. Eval (Container, "DataItem. ColumnName", null) %>
Other usage
<% # (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). Attributes. ToString () %> // If the attribute is of the string type, ToString () is not required.
Example of DataBinder. Eval usage
<% # DataBinder. Eval (Container. DataItem, "IntegerValue", "{0: c}") %>
The format string parameter is optional. If the parameter is ignored, DataBinder. Eval returns the object type value,
// Display two decimal places
<% # DataBinder. Eval (Container. DataItem, "UnitPrice", "$ {0: F2}") %>
// {0: G} indicates that True or False is displayed.
<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: g2.16.gif ") %> '/>
</ItemTemplate>
// Conversion Type
(String) DataBinder. Eval (Container, "DataItem. P_SHIP_TIME_SBM8"). Substring (4, 4)
{0: d} date only displays year, month, and day
{0: yyyy-mm-dd} displays year, month, and day by format
{0: c} currency Style
<% # 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.2420.e + 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 only displays year, month, and day
{0: yyyy-mm-dd} displays year, month, and day by format
The style depends on the settings in Web. config.
{0: c} or {0: 00000,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>
Displayed as listen 3,000.10
{0: c} or string. Format ("{0: C}", price); Chinese currency Style
<System. web>
<Globalization requestEncoding = "UTF-8" responseEncoding = "UTF-8" culture = "zh-cn" uiCulture = "zh-cn"/>
</System. web>
Shown as ¥3,000.10
{0: c} or string. Format ("{0: C}", price); American currency Style
<System. web>
<Globalization requestEncoding = "UTF-8" responseEncoding = "UTF-8"/>
</System. web>
Shown as $3,000.10