Databinder. Eval method (object, String, string) Usage

Source: Internet
Author: User

Databinder. Eval has three parameters: the name container of the data item, the name of the data field, and the formatted string.

In the template list, such as datalist, DataGrid, or repeater, the named container always container. dataitem.

(Msdn)
Databinder. Eval method (object, String, string)
Calculate the data binding expression at runtime and format the result to the text to be displayed in the request browser.
Namespace:System. Web. UI
Parameter container

The object reference calculated by the expression. This identifier must be a valid object identifier in the specified language of the page.

Expression

The navigation path from container to the public property value to be placed in the property of the bound control. This path must be a string of properties or field names separated by vertices, such"Tables [0]. defaultview. [0]. Price"Or in Visual Basic"Tables (0). defaultview. (0). Price".

Format

. NET Framework Format String, similar to the string used by string. format. You can convert an object (computation result of a data binding expression) to a string displayed by the requesting browser.

Return Value

StringIt is the result of calculation of the Data Binding expression and conversion to the string type.

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}") %>

Note:

Databinder is system. A static class in the Web, which provides the eval method to simplify writing data binding expressions. However, it uses reflection and other overhead methods to achieve ease of use, therefore, its performance is not the best.
The container is not a static object or method at all. It is processed by the ASP. NET page compiler in the Data Binding event.ProgramLocal variables declared internally are data container types of controls that can be bound to data (for example, the data binding container inside repeater is called repeateritem ), basically, these container classes have the dataitem attribute, so you can write container. dataitem, which returns the data item from the data source you are bound. If your data source is datatable, the Data Type of this data item is actually datarowview.

// {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
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

Http://blog.csdn.net/guye99/archive/2006/04/30/698323.aspx:

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.