Differences between eval ("") and databinder. eval (container. dataitem, "")

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.