A brief analysis of the differences between ES0en. Eval and Eval

  • 2020-06-23 00:11:32
  • OfStack

ASP. NET 2.0 improves data binding operations in templates by reducing the data binding syntax DataBinder. Eval(Container. DataItem, fieldname) in ES3en1.x to Eval(fieldname). The Eval method, like DataBinder.Eval1, accepts an optional format string argument. The shortened Eval syntax differs from DataBinder.Eval in that Eval automatically parses fields based on the DataItem attribute of the nearest container object, such as DataListItem, whereas ES21en.Eval requires parameters to specify the container. For this reason, Eval can only be used in templates for data-bound controls, not for the Page (page) layer. Of course, ASP.NET 2.0 still supports ES27en.Eval, and you can use it in environments where simplified Eval syntax is not supported.

Eval: Binding to the display of read-only data; Bind: You can bind either read-only data or update data. The Bind method also associates fields with the binding properties of controls, allowing methods like Update, Insert, and Delete of data controls (such as GridView, etc.) to use this association for processing.

Asp.net summary of DataBinder.Eval usage


<%# Bind("Subject") %> // Binding field 
<%# Container.DataItemIndex + 1%> // Realize automatic numbering 

The method usually used

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

Take two decimal places

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

Time formatting

<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-MM-dd}")%>
<%# Bind("AddinTime", "{0:yyyy-mm-dd}") %>

Eval and Bind bind data in < %# % > If you modify or manipulate the data you want to display < %# % > For example:

1. Display the displayed string as characters: < %# (Eval("Address")).ToString().SubString(0,10)% > , displays a 10-digit address.

2. Judge the displayed information: < % # (Eval (" if_delete ")). ToString = = "yes?" " Deleted ":" not deleted "% >


Related articles: