How to use Repeater Control in ASP.Net C# with Example

Bind Data using Repeater Control in Asp.Net

The ASP.NET Repeater is a basic container control that allows you to create custom lists from any data available to the page. When the page runs, the Repeater control loops through the records in the data source and renders an item for each record.
  • A table layout
  • A comma-delimited list (for example, a, b, c, d, and so on)
  • An XML formatted list
  • ItemTemplate Contains the HTML elements and controls to render once for each data item in the data source.
  • AlternatingItemTemplate Contains the HTML elements and controls to render once for every other data item in the data source. Typically, this template is used to create a different look for the alternating items, such as a different background color than the color that is specified in the ItemTemplate.
  • HeaderTemplate and FooterTemplate Contains the text and controls to render at the beginning and end of the list, respectively.
  • SeparatorTemplate Contains the elements to render between each item (A typical example might be a line).

Advantages of repeater control over grid view in C#

In simple words we can say performance of repeater is far better than gridview. If you need basic rendering for read only items then its better to use repeater and if you need events , pagination and editable controls then you should go for gridview. Simpler controls with less in built functionality are speedy. You can do implement all functionalities of grid view to repeater but you have to do it manually.

So it depends upon you requirements either you need repeater or gridview.

ASP.Net Repeater Control Example

The Repeater control is a container control that allows you to create custom lists out of any data that is available to the page. The Repeater control does not have a built-in rendering of its own, which means that you must provide the layout for the Repeater control by creating templates. 

Repeater control, ASP. NET Repeater, Repeater Web server control, repeater control, example c# code, display the data using repeater control
repeater control in example c# code
In the following example I will show how to display data in repeater control with C#. Find the sample code below :-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <title>C# - ASP.NET Repeater Control Example</title>
    <style type="text/css">
        .accordianContainer {
            max-height: 350px;
            overflow: auto;
        /*----------------Data Grid inside Pop up----------------------*/
        .CompApp_TableScroll {
            max-height: 255px;
            overflow: auto;

        .CompApp_DataTable {
            border-collapse: collapse;

            .CompApp_DataTable tr th {
                background-color: #dedede;
                color: #333333;
                padding: 5px;
                border: 1px solid #cccccc;
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
                font-weight: normal;
                white-space: nowrap;

            .CompApp_DataTable tr:nth-child(2n+2) {
                background-color: #f3f4f5;

            .CompApp_DataTable tr:nth-child(2n+1) td {
                background-color: #d6dadf;
                color: #454545;

            .CompApp_DataTable tr td {
                padding: 5px;
                color: #454545;
                font-family: Arial, Helvetica, sans-serif;
                font-size: 11px;
                border: 1px solid #cccccc;
                vertical-align: middle;
                text-align: left;
                white-space: nowrap;

                .CompApp_DataTable tr td:first-child {
                    text-align: left;
                    font-weight: bold;
                    text-align: left;
    <form id="form1" runat="server">
        <div class="accordianContainer">

            <asp:Repeater ID="rEmp" runat="server">
                    <h5>Display Data in ASP.NET Repeater Control ..</h5>
                    <table class="CompApp_DataTable">

                            <%# DataBinder.Eval(Container, "DataItem.EmpId")%>
                            <%# DataBinder.Eval(Container, "DataItem.Name")%>
                            <%# DataBinder.Eval(Container, "DataItem.Address")%>


                    <h5>Footer ..</h5>

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)

    private void BindRepeaterControl()
            DataTable dt = new DataTable();
            dt.Columns.Add("EmpId", typeof(int));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Address", typeof(string));

            dt.Rows.Add(25, "Rk", "Gurgaon");
            dt.Rows.Add(50, "Sachin", "Noida");
            dt.Rows.Add(10, "Nitin", "Noida");
            dt.Rows.Add(21, "Aditya", "Meerut");
            dt.Rows.Add(100, "Mohan", "Banglore");

            if (dt.Rows.Count > 0)
                rEmp.DataSource = dt;
        catch (Exception ex)
            throw ex;
I hope you will enjoy the development tip while programming with C# to bind data using repeater control and what are the advantages of using repeater control over gridview or datalist. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome. 

Also If you like this article, don't forget to share this article with your friends and colleagues. 

1 comment:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form


Email *

Message *

Powered by Blogger.