ASP. NET data binding expression

Source: Internet
Author: User

1. Data Binding expression

<Asp: literal id = "liteval1" runat = "server" text = '<% eval ("username") %>'/>
<% # Eval ("Date of Birth", "{0: d}") %>
<A href = '<% # eval ("userid", "default. aspx? Id = {0} ") %> '> <% # eval (" username ") %> </a>
<A href = '<% # string. Format ("default. aspx? Id = {0} & role = {1} ", Eval (" userid "), Eval (" userrole ") %> '> <% # eval (" username ") %> </a>

String variable bound to the background code (must be of the Public type)
1) Background code
Public string name = "Lonely sandcontinent ";
2) Front-end HTML code
<P> name: <% # name %> </P>

Bind to method:
<% # Getuserphoto (eval ("photopath") %>
Public String getuserphoto (Object photopath)
{
If (photopath = dbnull. Value) <% # (datarowview) container. dataitem) ["field name"] %>
Bind to dataview, able, Dataset
{
Return " ";
}
Else
{
Return " ";
}
}

Bind to datalist data item Template
<Asp: datalist id = "datalist1" repeatcolumns = "5" width = "600" runat = "server" performanceid = "objectperformance1">
<Itemtemplate>
<Asp: hyperlink id = "hyperlink1" runat = "server" navigateurl = '<% # eval ("photoid", "photoformviewplain. aspx? Id = {0} ") %> '>
<Asp: Image id = "image1" runat = "server" imageurl = '<% # eval ("FILENAME", "images/thumbs/{0 }") %> '/> </ASP: hyperlink>
<Asp: Label id = "captionlabel" runat = "server" text = '<% # eval ("caption") %>'/>
</Itemtemplate>
</ASP: datalist>

2 Differences Between eval and bind Methods

Eval is a one-way binding. It cannot write the modified data back to the data source, but BIND is a two-way binding. It can write the modified data back to the data source.

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.