Repeating yourself with the Repeater

Repeating yourself with the Repeater

The Repeater control is a templated control in ASP.NET that allows you to repeat a block of markup for each item in a collection of data. The Repeater control is useful for displaying data in a list or table format, and it is highly customizable and flexible.

To use the Repeater control, you need to define one or more templates that define the markup for the items in the collection. The most common templates are the ItemTemplate, which defines the markup for the items in the collection, and the AlternatingItemTemplate, which defines the markup for the alternate items in the collection.

Here’s an example of using the Repeater control to display a list of products:

<asp:Repeater ID=”rptProducts” runat=”server” DataSourceID=”dsProducts”>

    <ItemTemplate>

        <div class=”product”>

            <h3><%# Eval(“ProductName”) %></h3>

            <p><%# Eval(“Description”) %></p>

            <p>Price: <%# String.Format(“{0:C}”, Eval(“Price”)) %></p>

        </div>

    </ItemTemplate>

</asp:Repeater>

In this example, the Repeater control is bound to a data source named “dsProducts”, which contains a collection of products. The ItemTemplate is used to define the markup for each product in the collection, which consists of a product name, description, and price.

The content of the template includes data binding expressions, which are used to bind the values of the ProductName, Description, and Price fields to the markup of the control. The String.Format method is used to format the price value as a currency string.

Apply for ASP.NET Certification Now!!

https://www.vskills.in/certification/certified-aspnet-programmer

Back to Tutorial

Cookie setting or removal in PHP
Types of shares

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?