Here’s a complete concept and sample code for using a Repeater control in ASP.NET Web Forms with C#, perfect for displaying data from a SQL Server database.
What is a Repeater in ASP.NET?
The Repeater control is a data-bound control that renders a custom HTML layout for each record in a data source. Unlike GridView or ListView, Repeater offers full control over the output, making it lightweight and flexible.
Real-Time Example Scenario
Let’s say you want to display a list of IPOs (Initial Public Offerings) with Symbol, Company Name, and Listing Date in a clean format.
Step-by-Step Repeater Integration
ASPX Markup (with Repeater)
<asp:Repeater ID="rptIPOList" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="5">
<tr>
<th>Symbol</th>
<th>Company Name</th>
<th>Listing Date</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("Symbol") %></td>
<td><%# Eval("CompanyName") %></td>
<td><%# Eval("ListingDate", "{0:dd-MM-yyyy}") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
C# Code-Behind (Page_Load + SQL)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
string connStr = ConfigurationManager.ConnectionStrings["IPOOnline"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
string query = "SELECT Symbol, CompanyName, ListingDate FROM IPObidfiledetailsoffline";
using (SqlCommand cmd = new SqlCommand(query, conn))
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
rptIPOList.DataSource = rdr;
rptIPOList.DataBind();
}
}
}
Output
When this code runs, the Repeater will generate.
Symbol |
Company Name |
Listing Date |
ABC123 |
ABC Corp |
01-08-2025 |
XYZ789 |
XYZ Ltd |
05-08-2025 |
Why Use Repeater?
Feature |
Benefit |
Full HTML Control |
Customize layout, tags, CSS |
Lightweight |
No ViewState or server-side UI |
Fast Rendering |
Ideal for simple data display |
Tip
If you want paging or editing, use GridView instead. But for display-only lists with full HTML freedom, Repeater is best.