Sideway
output.to from Sideway
Draft for Information Only

Content

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.

Namespace

System.Web.UI.WebControls

Assembly

System.Web.dll public ref class Repeater : System::Web::UI::Control, System::Web::UI::INamingContainer public class Repeater : System.Web.UI.Control, System.Web.UI.INamingContainer type Repeater = class inherit Control interface INamingContainer Public 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

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="C#" AutoEventWireup="True" %>
       <script runat="server">
           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();
               }
           }

           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;
                   }
               }
           }
       </script>
    </head>
    <body>
       <%Response.Write("<p>Results on "+ Request.ServerVariables["SERVER_SOFTWARE"] + " .net: " + System.Environment.Version + "</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>
HTTP Response Output:
<!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">
    </head>
    <body>
       <p>Results on Microsoft-IIS/8.5 .net: 4.0.30319.42000</p><form method="post" action="./aspnet_comp_webforms_servercontrols_listcontrol_repeaterclass_01a_01.aspx" id="ctl00">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIMzA5NDQ1NDEPZBYCZg9kFgQCAQ8WAh4LXyFJdGVtQ291bnQCAxYGAgEPZBYCZg8VAglNaWNyb3NvZnQETXNmdGQCAg9kFgJmDxUCBUludGVsBEludGNkAgMPZBYCZg8VAgREZWxsBERlbGxkAgMPFgIfAAIDFgYCAQ9kFgJmDxUCCU1pY3Jvc29mdARNc2Z0ZAIDD2QWAmYPFQIFSW50ZWwESW50Y2QCBQ9kFgJmDxUCBERlbGwERGVsbGRkYp1kAEneW/NBrhxxQzjvjst977UpwWLnctcTMla6vwI=" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="1E70250F" />
</div>
           <h3>Repeater Example</h3>
           <b>Repeater1:</b>
           <p>
                       <table border=1>
                       <tr>
                           <td><b>Company</b></td>
                           <td><b>Symbol</b></td>
                       </tr>
                           <tr>
                        <td>
                             Microsoft
                        </td>
                        <td>
                             Msft
                        </td>
                   </tr>
                           <tr>
                        <td>
                             Intel
                        </td>
                        <td>
                             Intc
                        </td>
                   </tr>
                           <tr>
                        <td>
                             Dell
                        </td>
                        <td>
                             Dell
                        </td>
                   </tr>
                           </table>
                   <p>
           <b>Repeater2:</b>
           <p>
                       Company data:
                           Microsoft
                   (Msft)
                           ,
                           Intel
                   (Intc)
                           ,
                           Dell
                   (Dell)
               </form>
    </body>
</html>
HTML Web Page Embedded Output:

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>
HTTP Response Output:
<!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">
    </head>
    <body>
<p>Results on Microsoft-IIS/8.5 .net: 4.0.30319.42000 VB Version 14.0</p><form method="post" action="./aspnet_comp_webforms_servercontrols_listcontrol_repeaterclass_01a_02.aspx" id="ctl00">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIMzA5NDQ1NDEPZBYCZg9kFgQCAQ8WAh4LXyFJdGVtQ291bnQCAxYGAgEPZBYCZg8VAglNaWNyb3NvZnQETXNmdGQCAg9kFgJmDxUCBUludGVsBEludGNkAgMPZBYCZg8VAgREZWxsBERlbGxkAgMPFgIfAAIDFgYCAQ9kFgJmDxUCCU1pY3Jvc29mdARNc2Z0ZAIDD2QWAmYPFQIFSW50ZWwESW50Y2QCBQ9kFgJmDxUCBERlbGwERGVsbGRkArvHmALjnMYunzNkuavfyo8Y1vrV56kokjGwefLb+Yo=" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="587AFF99" />
</div>
           <h3>Repeater Example</h3>
           <b>Repeater1:</b>
           <p>
                       <table border=1>
                       <tr>
                           <td><b>Company</b></td>
                           <td><b>Symbol</b></td>
                       </tr>
                           <tr>
                        <td>
                             Microsoft
                        </td>
                        <td>
                             Msft
                        </td>
                   </tr>
                           <tr>
                        <td>
                             Intel
                        </td>
                        <td>
                             Intc
                        </td>
                   </tr>
                           <tr>
                        <td>
                             Dell
                        </td>
                        <td>
                             Dell
                        </td>
                   </tr>
                           </table>
                   <p>
           <b>Repeater2:</b>
           <p>
                       Company data:
                           Microsoft
                   (Msft)
                           ,
                           Intel
                   (Intc)
                           ,
                           Dell
                   (Dell)
               </form>
    </body>
</html>
HTML Web Page Embedded Output:

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

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="C#" %>
    </head>
    <body>
       <%Response.Write("<p>Results on "+ Request.ServerVariables["SERVER_SOFTWARE"] + " .net: " + System.Environment.Version + "</p>");%>
       <div id="Form1" runat="server">
           <h3>Repeater.DataSourceID Property Example</h3>

           <asp:Repeater id="Repeater1" 
               datasourceid="SqlDataSource1" 
               runat="server">

           <HeaderTemplate>
           <table border=1>
               <tr>
                   <td><b>Product ID</b></td>
                   <td><b>Product Name</b></td>
               </tr>
           </HeaderTemplate>

           <ItemTemplate>
           <tr>
                   <td> <%# Eval("ProductID") %> </td>
                   <td> <%# Eval("ProductName") %> </td>
               </tr>
           </ItemTemplate>

           <FooterTemplate>
           </table>
           </FooterTemplate>

           </asp:Repeater>

           <p>
           <asp:sqldatasource id="SqlDataSource1" 
           connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" 
               selectcommand="SELECT ProductID, ProductName FROM [Products] Where ProductID <= 10" 
               runat="server">
           </asp:sqldatasource>
       </div>
    </body>
</html>
HTTP Response Output:
<!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">
    </head>
    <body>
       <p>Results on Microsoft-IIS/8.5 .net: 4.0.30319.42000</p><div id="Form1">
           <h3>Repeater.DataSourceID Property Example</h3>

               <table border=1>
               <tr>
                   <td><b>Product ID</b></td>
                   <td><b>Product Name</b></td>
               </tr>
               <tr>
                   <td> 1 </td>
                   <td> Chai </td>
               </tr>
               <tr>
                   <td> 2 </td>
                   <td> Chang </td>
               </tr>
               <tr>
                   <td> 3 </td>
                   <td> Aniseed Syrup </td>
               </tr>
               <tr>
                   <td> 4 </td>
                   <td> Chef Anton's Cajun Seasoning </td>
               </tr>
               <tr>
                   <td> 5 </td>
                   <td> Chef Anton's Gumbo Mix </td>
               </tr>
               <tr>
                   <td> 6 </td>
                   <td> Grandma's Boysenberry Spread </td>
               </tr>
               <tr>
                   <td> 7 </td>
                   <td> Uncle Bob's Organic Dried Pears </td>
               </tr>
               <tr>
                   <td> 8 </td>
                   <td> Northwoods Cranberry Sauce </td>
               </tr>
               <tr>
                   <td> 9 </td>
                   <td> Mishi Kobe Niku </td>
               </tr>
               <tr>
                   <td> 10 </td>
                   <td> Ikura </td>
               </tr>
               </table>
    
           <p>
           </div>
    </body>
</html>
HTML Web Page Embedded Output:

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" %>
    </head>
    <body>
       <%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
       <div id="Form1" runat="server">
           <h3>Repeater.DataSourceID Property Example</h3>

           <asp:Repeater id="Repeater1" 
               datasourceid="SqlDataSource1" 
               runat="server">

           <HeaderTemplate>
           <table border=1>
               <tr>
                   <td><b>Product ID</b></td>
                   <td><b>Product Name</b></td>
               </tr>
           </HeaderTemplate>

           <ItemTemplate>
           <tr>
                   <td> <%# Eval("ProductID") %> </td>
                   <td> <%# Eval("ProductName") %> </td>
               </tr>
           </ItemTemplate>

           <FooterTemplate>
           </table>
           </FooterTemplate>

           </asp:Repeater>

           <p>
           <asp:sqldatasource id="SqlDataSource1" 
           connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" 
               selectcommand="SELECT ProductID, ProductName FROM [Products] Where ProductID <= 10" 
               runat="server">
           </asp:sqldatasource>
       </div>
    </body>
</html>
HTTP Response Output:
<!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">
    </head>
    <body>
       <p>Results on Microsoft-IIS/8.5 .net: 4.0.30319.42000 VB Version 14.0</p><div id="Form1">
           <h3>Repeater.DataSourceID Property Example</h3>

               <table border=1>
               <tr>
                   <td><b>Product ID</b></td>
                   <td><b>Product Name</b></td>
               </tr>
               <tr>
                   <td> 1 </td>
                   <td> Chai </td>
               </tr>
               <tr>
                   <td> 2 </td>
                   <td> Chang </td>
               </tr>
               <tr>
                   <td> 3 </td>
                   <td> Aniseed Syrup </td>
               </tr>
               <tr>
                   <td> 4 </td>
                   <td> Chef Anton's Cajun Seasoning </td>
               </tr>
               <tr>
                   <td> 5 </td>
                   <td> Chef Anton's Gumbo Mix </td>
               </tr>
               <tr>
                   <td> 6 </td>
                   <td> Grandma's Boysenberry Spread </td>
               </tr>
               <tr>
                   <td> 7 </td>
                   <td> Uncle Bob's Organic Dried Pears </td>
               </tr>
               <tr>
                   <td> 8 </td>
                   <td> Northwoods Cranberry Sauce </td>
               </tr>
               <tr>
                   <td> 9 </td>
                   <td> Mishi Kobe Niku </td>
               </tr>
               <tr>
                   <td> 10 </td>
                   <td> Ikura </td>
               </tr>
               </table>
    
           <p>
           </div>
    </body>
</html>
HTML Web Page Embedded Output:

Sources and References

  • https://docs.microsoft.com/en-us/troubleshoot/aspnet/server-controls
  • https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-1.1/c012haty(v=vs.71)
  • https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.repeater?redirectedfrom=MSDN&view=netframework-4.8

©sideway

ID: 211000004 Last Updated: 10/4/2021 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 68

Computer

Hardware 154

Software

Application 207

Digitization 25

Latex 35

Manim 203

Numeric 19

Programming

Web 285

Unicode 504

HTML 65

CSS 63

SVG 9

ASP.NET 240

OS 422

DeskTop 7

Python 64

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 32

Coordinate Geometry 1

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2021 Sideway . All rights reserved Disclaimers last modified on 06 September 2019