ASP. NET 2.0 improves the Data Binding operation in the template. It simplifies 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 formatted string parameter. Shortened Eval syntax and DataBinder. the difference between Eval is that Eval will automatically parse fields based on the DataItem attribute of the most recent container object (such as DataListItem), while DataBinder. eval needs to use parameters to specify the container. For this reason, Eval can only be used in the template of the data-bound control, but cannot be used in the Page layer. Of course, the ASP. NET 2.0 page still supports DataBinder. Eval. You can use it in environments that do not support simplified Eval syntax.
Eval: displays read-only data. Bind: You can Bind read-only data or update data. The Bind method also associates fields with the binding property of the control, this makes it possible to use the Update, Insert, and Delete methods of data controls (such as the GridView) for corresponding processing.
Summary of DataBinder. Eval usage in Asp.net
Copy codeThe Code is as follows:
<% # Bind ("Subject") %> // Bind a field
<% # Container. DataItemIndex + 1%> // implement automatic numbering
Common method
Copy codeThe Code is as follows:
<% # DataBinder. Eval (Container. DataItem, "ColumnName") %>
<% # (Bool) DataBinder. Eval (Container. DataItem, "BoolValue") %>
Decimal places
Copy codeThe Code is as follows:
<% # DataBinder. Eval (Container. DataItem, "UnitPrice", "{0: F2}") %>
Time Format
Copy codeThe Code is as follows:
<% # DataBinder. Eval (Container. DataItem, "Company_Ureg_Date", "{0: yyyy-MM-dd}") %>
<% # Bind ("AddinTime", "{0: yyyy-mm-dd}") %>
The data bound to Eval and Bind is displayed in <% # %>. If you modify or operate the data to be displayed, it is also in <% # %>. For example:
1. display the displayed strings as characters: <% # (Eval ("Address"). ToString (). SubString () %>. display the 10-digit Address.
2. Determine the displayed information: <% # (Eval ("if_delete"). ToString = "yes "? "Deleted": "Not deleted" %>