

Navigator : Home > Tutorials > Controls Tutorials > ...
How to use repeater control in ASP.NET 2.0(C#)
The Repeater control is used to display a repeated list of items that are bound to the control. It enable the customization of the layout by each repeated list of items. The Repeater control may be bound to a database table, an XML file, or another list of items. The Repeater control has no built-in select and edit support.
Below are 2 simple Repeater controls. The first one display its items in a table, and the second one display its items separated by comma.
Define PositionData Class
If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.
public class PositionData {
private string name; private string ticker; public PositionData(string name, string ticker) {
this.name = name; this.ticker = ticker; } public string Name {
} public string Ticker {
} |
Invoking PositionData to add data, and use Repeater1, Repeater2 to bind data
display
void Page_Load(Object Sender, EventArgs e) {
if (!IsPostBack) {
ArrayList values = new ArrayList();
values.Add(new PositionData("Microsoft", "Msft")); values.Add(new PositionData("Intel", "Intc")); values.Add(new PositionData("Dell", "Dell"));
Repeater1.DataSource = values; Repeater1.DataBind();
Repeater2.DataSource = values; Repeater2.DataBind(); } } |
The front page of Repeater.aspx page
<head runat="server"> <title>Repeater</title> </head> <body> <form id="Form1" runat="server">
<b> Repeater1:</b> <p> <asp:Repeater id="Repeater1" runat="server" > <HeaderTemplate> <table border=1> <tr> <td><b>Company</b></td> <td><b>Symbol</b></td> </tr> </HeaderTemplate>
<ItemTemplate> <tr> <td> <%# DataBinder.Eval(Container.DataItem, "Name") %> </td> <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %> </td> </tr> </ItemTemplate>
<FooterTemplate> </table> </FooterTemplate>
</asp:Repeater> <p>
<b>Repeater2:</b> <p> <asp:Repeater id="Repeater2" runat="server" >
<HeaderTemplate> Company data: </HeaderTemplate>
<ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Name") %> (<%# DataBinder.Eval(Container.DataItem, "Ticker") %>) </ItemTemplate>
<SeparatorTemplate>, </SeparatorTemplate> </asp:Repeater> </form> </body> </html> |
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!