-------DataBinder All usages------------------<%# bind ("Subject")%>//bound field
<%# Container.dataitemindex + 1%>//implement auto-numbering
<%# DataBinder.Eval (Container.DataItem, "
")%>
common methods of use
<%# 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)
%>
<%# ((DbDataRecord) Container.DataItem) [0]%>
<%# ((custom type) Container.DataItem). property. ToString ()%>//If the property is a string type, do not use ToString ()
DataBinder.Eval Usage Examples
<%# DataBinder.Eval (Container.DataItem, "IntegerValue", "{0:c}")%>
Formatting string parameters is optional. If the parameter is omitted, DataBinder.Eval returns the value of the object type.
Show two decimal places
<%# DataBinder.Eval (Container.DataItem, "UnitPrice", "${0:f2}")%>
{0:g} represents display True or false
<ItemTemplate>
<asp:image width= "height=" border= "0" runat= "Server"
Alternatetext= ' <%# DataBinder.Eval (Container.DataItem, "discontinued", "{0:g}")%> '
Imageurl= ' <%# DataBinder.Eval (Container.DataItem, "discontinued", "~/images/{0:g}.gif")%> '/>
</ItemTemplate>
Conversion type
(string) DataBinder.Eval (Container, "DATAITEM.P_SHIP_TIME_SBM8")). Substring (bis)
{0:D} date only displays month date
{0:YYYY-MM-DD} displays month date by format
{0:C} currency style
<% #Container. DataItem ("Price", "{0:¥#,# #0. xx}")%>
<%# 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 only displays month date
{0:YYYY-MM-DD} displays month date by format
Style depends on settings in Web. config
{0:c} or {0:£0,000.00} currency style standard UK currency style
<system.web>
<globalization requestencoding= "Utf-8" responseencoding= "Utf-8" culture= "en-us" uiculture= "en-US"/>
</system.web>
Display as £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>
Display 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>
Display as $3,000.10
What is the difference between DataBinder.Eval (Container.DataItem, "name") and Container.DataItem ("name")?
DataBinder is a static class inside the system.web that provides the Eval method for simplifying the writing of data-binding expressions, but it uses a much more expensive method such as reflection to achieve ease of use, so its performance is not the best. And container is not a static object or method at all. It is a local variable that the ASP. NET page compiler declares inside a data-bound event handler whose type is the data container type of the control that can be data-bound (for example, the data-binding container inside the repeater is called RepeaterItem), which basically has the DataItem attribute in these container classes, so you can write C Ontainer. DataItem, this property returns the data item in the data source that you are binding. If your data source is a DataTable, the type of the data item is actually DataRowView.