Simplified eval data binding syntax for binding to DataList data item templates

Source: Internet
Author: User
Tags definition bind eval net

Bind is a two-way binding, but requires that the data source be changed to be used. ASP.net 2.0 improves data-binding operations in the template, simplifying 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 format string parameter. The difference between the shortened eval syntax and the DataBinder.Eval is that Eval automatically parses the fields based on the DataItem properties of the nearest container object (such as DataListItem), and DataBinder.Eval needs to use parameters to specify the container. For this reason, eval can only be used in a data-bound control's template, not the page layer. Of course, DataBinder.Eval is still supported on the ASP.net 2.0 page, and you can use it in an environment that does not support simplified Eval syntax.

The following example shows how to use the new simplified eval data binding syntax to bind to the image, label, and Hyperlink controls in the DataList data item template (ItemTemplate).

The following are the referenced contents:

= "5" width= "runat=" "Server" DataSourceID
= "ObjectDataSource1" >

= "Server" Navigateurl= ' <%# Eval ("PhotoID",
"Photoformviewplain.aspx?id={0}")%> ' >
= "Server" Imageurl= ' <%# Eval ("FileName",
"Images/thumbs/{0}")%> '/>
= ' <%# Eval ("Caption")%> '/>



= "Server" TypeName
= "Datacomponenttableadapters.photostableadapter
"Selectmethod=" Getphotosforalbum "

Bindings can also be part of the subject definition of a control (theme definition) so that we can change the layout and appearance of the templated control arbitrarily by changing the theme. However, the theme (subject) template can only use eval (or the bind discussed later). Binding to arbitrary user code is prohibited.



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.