On the difference between DataBinder.Eval and eval--practical skills

Source: Internet
Author: User

ASP.net 2.0 improves data-binding operations in the template, simplifying the data-binding syntax DataBinder.Eval (Container.DataItem, fieldname) in v1.x to Eval (fieldname). The Eval method, like DataBinder.Eval, can accept an optional format string parameter. The difference between the shortened eval syntax and the DataBinder.Eval is that Eval automatically parses the fields based on the DataItem properties of the nearest container object (such as DataListItem), and DataBinder.Eval needs to use parameters to specify the container. For this reason, eval can only be used in a data-bound control's template, not the page layer. Of course, DataBinder.Eval is still supported on the ASP.net 2.0 page, and you can use it in an environment that does not support simplified Eval syntax.

Eval: Binding is the display of read-only data; bind: You can bind read-only data or bind update data, and the Bind method also links the binding properties of fields and controls so that data controls (such as the GridView, etc.) update, Methods such as insert and delete can use this connection to make the appropriate processing.

Summary of the usage of DataBinder.Eval in asp.net

Copy Code code as follows:

<%# bind ("Subject")%>//bound field
<%# Container.dataitemindex + 1%>//implementation automatic numbering

Commonly used methods
Copy Code code as follows:

<%# DataBinder.Eval (Container.DataItem, "ColumnName")%>

<%# (BOOL) DataBinder.Eval (Container.DataItem, "Boolvalue")%>


Take two decimal places
Copy Code code as follows:

<%# DataBinder.Eval (Container.DataItem, "UnitPrice", "{0:F2}")%>

Time formatting
Copy Code code as follows:

<%# DataBinder.Eval (Container.DataItem, "company_ureg_date", "{0:YYYY-MM-DD}")%>

<%# Bind ("Addintime", "{0:YYYY-MM-DD}")%>


The Eval and bind-bound data is displayed in <%#%>, and if the data to be displayed is modified or manipulated in <%#%>, for example:

1, display the string as a character display: <%# (Eval ("Address")). ToString (). SubString (0,10)%>, displaying a 10-digit address.

2, judge the information displayed: <%# (Eval ("If_delete")). ToString = = "Yes"? Deleted ': ' Not deleted '%>

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.