Eval ("") and bind ("") one-way binding and one-way binding
BIND is a two-way binding, but can be used only when the data source can be changed
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.
The following example demonstrates how to bind a new simplified eval Data Binding syntax to the image, label, and hyperlink controls in the datalist data item template (itemtemplate.
<Asp: datalist id = "datalist1" repeatcolumns = "5" width = "600" runat = "server" performanceid = "objectperformance1">
<Itemtemplate>
<Asp: hyperlink id = "hyperlink1" runat = "server" navigateurl = & apos; <% # eval ("photoid", "photoformviewplain. aspx? Id = {0} ") %> & apos;>
<Asp: Image id = "image1" runat = "server" imageurl = & apos; <% # eval ("FILENAME", "images/thumbs/{0 }") %> & apos;/> </ASP: hyperlink>
<Asp: Label id = "captionlabel" runat = "server" text = & apos; <% # eval ("caption") %> & apos;/>
</Itemtemplate>
</ASP: datalist> <br/>
<Asp: objectdatasource id = "objectperformance1" runat = "server" typename = "datacomponenttableadapters. photostableadapter" selectmethod = "getphotosforalbum">
Data Binding can also be part of the theme definition of the control, so that we can freely change the layout and appearance of the templated control by changing the theme. However, the theme template can only use eval (or bind discussed later ). Binding to any user code is forbidden.