Repeater Class Definition Namespace Assembly Inheritance Derived Implements Repeater Web Server Control Examples Examples of Visual C# ASP.NET Repeater Web Server Control Examples of Visual Basic ASP.NET Repeater Web Server Control Repeater Web Server Control with DataSourceID Examples Examples of Visual C# ASP.NET Repeater Web Server Control Examples of Visual Basic ASP.NET Repeater Web Server Control Sources and References
Repeater Class
Definition
A data-bound list control that allows custom layout by repeating a specified template for each item displayed in the list.
System.Web.dll
public ref class Repeater : System::Web::UI::Control, System::Web::UI::INamingContainerpublic class Repeater : System.Web.UI.Control, System.Web.UI.INamingContainertype Repeater = class
inherit Control
interface INamingContainerPublic Class Repeater
Inherits Control
Implements INamingContainer
Inheritance
Object->
Control->
Repeater
Derived
System.Web.DynamicData.FilterRepeater
Implements
INamingContainer
Repeater Web Server Control Examples
The following code example demonstrates how to use two simple Repeater controls on a page. The DataSource property is used to specify the data source for the Repeater control. The first Repeater displays its items in a table; the second Repeater displays its items in a comma-separated list.
Examples of Visual C# ASP.NET Repeater Web Server Control
Examples of Visual Basic ASP.NET Repeater Web Server Control
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<%@ Page Language="VB" AutoEventWireup="True" %>
<script runat="server" >
Sub Page_Load(Sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values As 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()
End If
End Sub
Public Class PositionData
Private myName As String
Private myTicker As String
Public Sub New(newName As String, newTicker As String)
Me.myName = newName
Me.myTicker = newTicker
End Sub
Public ReadOnly Property Name() As String
Get
Return myName
End Get
End Property
Public ReadOnly Property Ticker() As String
Get
Return myTicker
End Get
End Property
End Class
</script>
</head>
<body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
<form runat="server">
<h3>Repeater Example</h3>
<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>
Repeater Web Server Control with DataSourceID Examples
The following code example demonstrates how to use the DataSourceID property to specify the data source for a Repeater control. The DataSourceID property is set to the ID property of the SqlDataSource control used to retrieve the data. When the page is loaded, the Repeater control automatically binds to the data source specified by the SqlDataSource control and the data is displayed to the user.
Examples of Visual C# ASP.NET Repeater Web Server Control