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