ASP. NET 2.0 Tutorial: Bind tag and Eval tag

Source: Internet
Author: User

In ASP. the Bind and Eval labels introduced in NET 2.0 simplify DataBinder in 1.1. eval. in most cases, you will not notice the major differences between the two new tags. However, you may find that the code generated by the VS editor on the design interface uses Bind by default, there may be two main reasons:

Eval binds Data Using Reflection on the backend, so the speed is slow.
Eval is usually used to display read-only data. Bind supports direct integration with controls such as xxxDataSource.
Maybe the Bind is based on this consideration (Automatic Binding of Update and other methods), similar to the following method will not work as we think:

1: Text = '<% # Bind ("ApplicationName") + "-" + Bind ("WorkItemId") %>'

The last displayed result is the Bind ("WorkItemId") result. All the preceding results, including the connection string, are omitted. as you can imagine, because the Bind tries to automatically update the database back (even if you didn't do so), the automatic update mechanism for binding multiple fields may not be able to be determined. in this case, you can use Eval instead. of course, to achieve the best performance, you should use explicit type conversion, as shown below:

1: Text = '<% # (System. Data. DataRowView) Container. DataItem) ["ApplicationName"]
2: + "-" + (System. Data. DataRowView) Container. DataItem) ["WorkItemId"] %>'

Note: The preceding example assumes that the data source is a weak DataSet.

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.