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.
The cold Sand Island is lonely.
From Lonely sandcontinent