Differences between DataBinder. Eval and Eval

Source: Internet
Author: User

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" %>

Related Article

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.