How to Repeater

The ASP.NET Repeater control is a fundamental container control that provides developers with the ability to create customized lists from any data available on the web page. It offers a highly flexible and adaptable interface, allowing developers to tailor the appearance and behavior of the list to their specific requirements.

Does not come with a pre-defined layout

Unlike some other controls, the Repeater control does not come with a pre-defined layout or styles. This means that developers need to explicitly declare and configure all layout, formatting, and style tags within the control's templates. By doing so, developers have full control over the visual representation and styling of the list.

<asp:Repeater id="repeater1" runat="server" > <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "stor_id")%> </ItemTemplate> </asp:Repeater>

Every Repeater control requires at least one ItemTemplate. The ItemTemplate specifies the layout and structure for each item in the list. Within the ItemTemplate, developers can define HTML markup, controls, and data-binding expressions to display the data from the data source.

The Repeater control excels at rendering HTML to display the contents of a list or data source it is bound to. If the Repeater control's data source is set, but no data is returned from the data source, the control will still render without any items. However, if the data source is set to Nothing, the Repeater control will not be rendered at all.

To demonstrate the usage of the Repeater control, the following ASP.NET program showcases how to display data using the Repeater control. This program provides a practical example of how to set up and utilize the Repeater control to render a list of items from a data source.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Repeater id="repeater1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "stor_id")%>    <%# DataBinder.Eval(Container.DataItem, "stor_name")%> <br /> </ItemTemplate> </asp:Repeater> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>" SelectCommand="select [stor_id],[stor_name] from stores" /> </div> </form> </body> </html>


By using the Repeater control's flexibility and customizable features, developers can create dynamic and visually appealing lists that seamlessly integrate with their ASP.NET applications. The Repeater control is a powerful tool for presenting data in a structured and user-friendly manner, enhancing the overall user experience.