Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - How to use repeater control in ASP.NET 2.0(C#)
How to use repeater control in ASP.NET 2.0(C#)


ASP.NET Controls Tutorial

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

public class PositionData
{
private string name;
private string ticker;

public PositionData(string name, string ticker)
{
this.name = name;
this.ticker = ticker;
}

public string Name
{
get
{
return name;
}
}

public string Ticker
{
get
{
return ticker;
}
}

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!

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();
}
}

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

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>

Download the Full Working Version of this Project written with Visual Studio.NET C# 2005 Here!

Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!







 
  Developer Resources







Server Intellect Rocks