Show database-related data
The appearance is separated from the data.
Appearance code: use template to implement. (Head, foot, item, alternating item, delimiter template)
HeaderTemplate Header Template
FooterTemplate Foot Template
ItemTemplate Item Template
AlternatingItemTemplate Alternating Item Templates
SeparatorTemplate Separator Template
1. Add the Repeater control to the design page
2. Add a template to the <> source page
<asp:repeater id="Repeater1 " runat="server"> <HeaderTemplate> <ul> </HeaderTemplate> <ItemTemplate> <li> <%# Eval ("Name")%></li> </ItemTemplate> < footertemplate> </ul> </FooterTemplate> </asp:Repeater>
3. Binding data in a. cs file
var query = context. Info; = query; Repeater1.databind ();
Repeater three ways to bind data in a template:
1. <%# Eval ("Property name or column name", "format")%>
<%# Eval ("Birthday","{0:yyyy mm month DD day}")%>
2, <%# function name ()%>, function needs to be written in the. cs file beforehand and return a string. Such as:
Public string Showsexname () { bool sex = Convert.toboolean (Eval ("sex")); return " male " " female " ; }
3. If you are using an entity class (such as LINQ), you can extend the attribute to bind using <%# Eval ("extended attribute")%> in the template.
<td><%# Eval ("nation1.name")%></td>
Data Control (Repeater)