String. format in asp tutorial. net eval
<Asp: datalist id = "datalist1" repeatcolumns
= "5" width = "600" runat = "server" performanceid
= "Objectperformance1">
<Itemtemplate>
<Asp: hyperlink id = "hyperlink1" runat
= "Server" navigateurl = & apos; <% # eval ("photoid ",
"Photoformviewplain. aspx? Id = {0} ") %> & apos;>
<Asp: image id = "image1" runat
= "Server" imageurl = & apos; <% # eval ("filename ",
"Images/thumbs/{0}") %> & apos;/> </asp: hyperlink>
<Asp: label id = "captionlabel" runat = "server" text
= & Apos; <% # eval ("caption") %> & apos;/>
</Itemtemplate>
</Asp: datalist> <br/>
<Asp: objectdatasource id = "objectperformance1" runat
= "Server" typename
= "Datacomponenttableadapters. photostableadapter
"Selectmethod =" getphotosforalbum ">
<% # 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
One thing you should know is that an attribute is actually composed of a pair of get/set methods (of course, one of them may be missing ). After obtaining the propertyinfo object of an attribute, you can use its getsetmethod method to obtain its setting method. The following work can not be handed over to "direct call of methods, reflection call and ...... Is dynamicmethodexecutor in lambda expression call? Therefore, it is easy to add a setvalue method for dynamicpropertyaccessor:
Public class dynamicpropertyaccessor
{
...
Private dynamicmethodexecutor m_dynamicsetter;
...
Public dynamicpropertyaccessor (propertyinfo)
{
...
Methodinfo setmethod = propertyinfo. getsetmethod ();
If (setmethod! = Null)
{
This. m_dynamicsetter = new dynamicmethodexecutor (setmethod );
}
}
...
Public void setvalue (object o, object value)
{
If (this. m_dynamicsetter = null)
{
Throw new notsupportedexception ("cannot set the property .");
}
This.m_dynamicsetter.exe cute (o, new object [] {value });
}
}