Sideway
output.to from Sideway
Draft for Information Only

Content

Repeater Web Server Control
 Remarks
 Simple 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 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 Web Server Control

Creates a data-bound list control that allows custom layout by repeating a specified template for each item displayed in the list.

Remarks

Use the Repeater control to create a basic templated data-bound list. The Repeater control has no built-in layout or styles; you must explicitly declare all HTML layout, formatting, and style tags within the control's templates.

The Repeater control is different from other data list controls in that it allows you to place HTML fragments in its templates. This allows you to create a complex HTML structure, such as a table. For example, to create a list within an HTML table, start the table by placing the <table> tag in the HeaderTemplate. Next, create the rows and columns of the table by placing <tr> tags, <td> tags, and data-bound items in the ItemTemplate. If you want a different appearance for alternating items in the table, create an AlternatingItemTemplate with the same contents as the ItemTemplate, except with a different style specified. Finally, complete the table by placing the </table> tag in the FooterTemplate.

The following table lists the different templates of the Repeater control.
TemplateDescription AlternatingItemTemplateLike the ItemTemplate element, but rendered for every other row (alternating items) in the Repeater control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties. FooterTemplateElements to render once, after all data-bound rows have been rendered. A typical use is to close an element opened in the HeaderTemplate item (with a tag such as </table>). Note: The FooterTemplate cannot be data bound. HeaderTemplateElements to render once, before any data-bound rows have been rendered. A typical use is to begin a container element, such as a table. Note: The HeaderTemplate item cannot be data bound. ItemTemplate Elements that are rendered once for each row in the data source. To display data in the ItemTemplate, declare one or more Web server controls and set their data-binding expressions to evaluate to a field in the Repeater control's (that is, the container control's) DataSource. The following example shows a sample declaration that displays the field containing the first name in a Label control. First Name: <asp:Label runat="server" Text="<%# Container.DataItem.FirstName %>" /> SeparatorTemplateElements to render between each row, typically line breaks (<br> tags), horizontal lines (<hr> tags), and so on. Note The SeparatorTemplate item cannot be data bound.

The Repeater control has no built-in selection or editing support. You can create a handler for the control's ItemCommand event to process control events that are sent from the templates to the control.

The control binds its Item and AlternatingItem templates to a data structure referenced in the control's DataSource property. (The Header, Footer, and Separator templates cannot be bound to data.) If the Repeater control's DataSource property is set but no data is returned, the control renders the Header and Footer templates, but no items. If the DataSource property is not set, the Repeater control is not rendered.

CAUTION Text is not HTML encoded before it is displayed in the Repeater control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.

Simple Repeater Web Server Control Examples

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#"%>
       <script runat="server" >
           public void Page_Load()
           {
               String[] myStringArray = new String[] {"one","two","three"};
               rptr.DataSource = myStringArray;
               rptr.DataBind();
           }
       </script>
    </head>
    <body>
       <%Response.Write("<p>Results on "+ Request.ServerVariables["SERVER_SOFTWARE"] + " .net: " + System.Environment.Version + "</p>");%>
       <asp:repeater id=rptr runat="server">
           <itemtemplate><%# Container.DataItem %><br></itemtemplate>
       </asp:repeater>
    </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>one<br>two<br>three<br>
    </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"%>
       <script runat="server" >
           public sub Page_Load()
               Dim myStringArray as String()
               myStringArray = new String() {"one","two","three"}
               rptr.DataSource = myStringArray
               rptr.DataBind()
           end sub
       </script>
    </head>
    <body>
       <%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
       <asp:repeater id=rptr runat="server">
           <itemtemplate><%# Container.DataItem %><br></itemtemplate>
       </asp:repeater>
    </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>one<br>two<br>three<br>
    </body>
</html>
HTML Web Page Embedded Output:

Repeater Web Server Control Examples

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_repeater_01a_03.aspx" id="ctl00">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIMzA5NDQ1NDEPZBYCZg9kFgQCAQ8WAh4LXyFJdGVtQ291bnQCAxYGAgEPZBYCZg8VAglNaWNyb3NvZnQETXNmdGQCAg9kFgJmDxUCBUludGVsBEludGNkAgMPZBYCZg8VAgREZWxsBERlbGxkAgMPFgIfAAIDFgYCAQ9kFgJmDxUCCU1pY3Jvc29mdARNc2Z0ZAIDD2QWAmYPFQIFSW50ZWwESW50Y2QCBQ9kFgJmDxUCBERlbGwERGVsbGRksfwUPjx9QKC+IF7gk0ebSGqlGl1XqfSLEOp2GwDB69g=" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="6730CDE9" />
</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_repeater_01a_04.aspx" id="ctl00">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIMzA5NDQ1NDEPZBYCZg9kFgQCAQ8WAh4LXyFJdGVtQ291bnQCAxYGAgEPZBYCZg8VAglNaWNyb3NvZnQETXNmdGQCAg9kFgJmDxUCBUludGVsBEludGNkAgMPZBYCZg8VAgREZWxsBERlbGxkAgMPFgIfAAIDFgYCAQ9kFgJmDxUCCU1pY3Jvc29mdARNc2Z0ZAIDD2QWAmYPFQIFSW50ZWwESW50Y2QCBQ9kFgJmDxUCBERlbGwERGVsbGRkLWvp7B5uwz6LfP9C9zUNCyFQve7yIMJBdTDRPxmtUKs=" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="7F18F433" />
</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:

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)

©sideway

ID: 211000002 Last Updated: 10/2/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

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

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-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019