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.