2.0 improves data binding operations in templates, simplifying the data binding syntax (, fieldname) in it to Eval(fieldname). The Eval method can also accept an optional formatted string parameter. The difference between shortened Eval syntax is that Eval automatically parses fields based on the DataItem property of the nearest container object (such as DataListItem), and requires parameters to specify the container. For this reason, Eval can only be used in templates of data binding controls, and cannot be used in the Page layer. Of course, it is still supported in the 2.0 page, and you can use it in an environment that does not support the simplified Eval syntax.
Eval: The display of read-only data is bound; Bind: You can bind read-only data or bind update data. The Bind method also links fields with the binding properties of the control, so that the Update, Insert and Delete methods of data controls (such as GridView, etc.) can use this connection to make corresponding processing.
Summary of usage in
<%# Bind("Subject") %> //Binding fields
<%# + 1%> //Implement automatic numbering
Commonly used methods
<%# (, "ColumnName") %>
<%# (bool)(, "BoolValue") %>
Take two decimal places
<%# (, "UnitPrice", "{0:F2}") %>
Time formatting
<%# (,"Company_Ureg_Date","{0:yyyy-MM-dd}")%>
<%# Bind("AddinTime", "{0:yyyy-mm-dd}") %>
The data bound to Eval and Bind is displayed in <%# %>. If the data to be displayed is modified or operated in <%# %>, for example:
1. Display the displayed string character: <%# (Eval("Address")).ToString().SubString(0,10)%>, displaying the 10-digit address.
2. Make judgments on the displayed information: <%# (Eval("if_delete")).ToString == "yes" ?"Deleted":"Not deleted"%>