Summary of databinder. Eval usage in Asp.net

Source: Internet
Author: User
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

<% # 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.