aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Repeater Control example in

Jan 14, 2012

In this article I will explain what is repeater control, uses of repeater control and how to bind data to repeater control in

In previous posts I explained many articles regarding Gridview, Ajax, JQuery and many more. Now I will explain about what is repeater control, uses of repeater control, bind data to repeater control in
What is Repeater Control?
Repeater Control is a control which is used to display the repeated list of items
Uses of Repeater Control
Repeater Control is used to display repeated list of items that are bound to the control and it’s same as gridview and datagridview. Repeater control is lightweight and faster to display data when compared with gridview and datagrid. By using this control we can display data in custom format but it’s not possible in gridview or datagridview and it doesn’t support for paging and sorting.  
The Repeater control works by looping through the records in your data source and then repeating the rendering of it’s templates called item template. Repeater control contains different types of template fields those are
1) itemTemplate 2) AlternatingitemTemplate 3) HeaderTemplate 4) FooterTemplate
5) SeperatorTemplate
ItemTemplate: ItemTemplate defines how the each item is rendered from data source collection.

AlternatingItemTemplate: AlternatingItemTemplates is used to change the background color and styles of AlternatingItems in DataSource collection 

HeaderTemplate: HeaderTemplate is used to display Header text for DataSource collection and apply different styles for header text.

FooterTemplate: FooterTemplate is used to display footer element for DataSource collection

SeparatorTemplate: SeparatorTemplate will determine separator element which separates each Item in Item collection. Usually, SeparateTemplate will be <br> html element or <hr> html element.

To implement repeater control sample first design table in your database as shown below

Column Name
Data Type
Allow Nulls
int(set identity property=true)

After completion of table creation Open Visual Studio and create new website after that write the following code in your aspx page  

<html xmlns="">
<head runat="server">
<title>Repeator Control Example</title>
<form id="form1" runat="server">
<td>Enter Name: </td>
<td><asp:TextBox ID="txtName" runat="server"/></td>
<td>Enter Subject: </td>
<td><asp:TextBox ID="txtSubject" runat="server"/></td>
<td valign="top">Enter Comments:</td>
<td><asp:TextBox ID="txtComment" runat="server" Rows="5" Columns="20" TextMode="MultiLine"/></td>
<td><asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" /></td>
<asp:Repeater ID="RepDetails" runat="server">
<table style=" border:1px solid #df5015; width:500px" cellpadding="0">
<tr style="background-color:#df5015; color:White">
<td colspan="2">
<tr style="background-color:#EBEFF0">
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015; width:500px" >
<asp:Label ID="lblSubject" runat="server" Text='<%#Eval("Subject") %>' Font-Bold="true"/>
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("Comment") %>'/>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015;border-bottom:1px solid #df5015; width:500px" >
<td>Post By: <asp:Label ID="lblUser" runat="server" Font-Bold="true" Text='<%#Eval("UserName") %>'/></td>
<td>Created Date:<asp:Label ID="lblDate" runat="server" Font-Bold="true" Text='<%#Eval("PostedDate") %>'/></td>
<td colspan="2">&nbsp;</td>
After completion of aspx page design add following namespaces in code behind

C# Code

using System;
using System.Data;
using System.Data.SqlClient;
After add namespace write the following code

private SqlConnection con = new SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true");
protected void Page_Load(object sender, EventArgs e)
// This button click event is used to insert comment details and bind data to repeater control
protected void btnSubmit_Click(object sender, EventArgs e)
SqlCommand cmd = new SqlCommand("insert into Repeater_Table (UserName,Subject,Comment,PostedDate) values(@userName,@subject,@comment,@postedDate)", con);
cmd.Parameters.AddWithValue("@userName", txtName.Text);
cmd.Parameters.AddWithValue("@subject", txtSubject.Text);
cmd.Parameters.AddWithValue("@comment", txtComment.Text);
cmd.Parameters.AddWithValue("@postedDate", DateTime.Now);
txtName.Text = string.Empty;
txtSubject.Text = string.Empty;
txtComment.Text = string.Empty;
//Bind Data to Repeater Control
protected void BindRepeaterData()
SqlCommand cmd = new SqlCommand("select * from Repeater_Table Order By PostedDate desc", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
RepDetails.DataSource = ds;

Imports System.Data
Imports System.Data.SqlClient

Partial Public Class Default2
Inherits System.Web.UI.Page
Private con As New SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
End If
End Sub
' This button click event is used to insert comment details and bind data to repeater control
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim cmd As New SqlCommand("insert into Repeater_Table (UserName,Subject,Comment,PostedDate) values(@userName,@subject,@comment,@postedDate)", con)
cmd.Parameters.AddWithValue("@userName", txtName.Text)
cmd.Parameters.AddWithValue("@subject", txtSubject.Text)
cmd.Parameters.AddWithValue("@comment", txtComment.Text)
cmd.Parameters.AddWithValue("@postedDate", DateTime.Now)
txtName.Text = String.Empty
txtSubject.Text = String.Empty
txtComment.Text = String.Empty
End Sub
'Bind Data to Repeater Control
Protected Sub BindRepeaterData()
Dim cmd As New SqlCommand("select * from Repeater_Table Order By PostedDate desc", con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
If ds.Tables(0).Rows.Count > 0 Then
RepDetails.Visible = True
RepDetails.DataSource = ds
RepDetails.Visible = False
End If
End Sub
End Class
Now run in your application and check the output


Download sample code attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Ajay Patil said...

Awesome , friend good job .............very helpful

SAUROV HALDER 333 said...

It's amazing ....The best site I have ever found for self to keep in touch...Keep it

Nitin said...

great site thanx for all suresh

RaViNdRa PaRcHa said...

wooo.......great man .... Best learning site ever seen.

sahil gupta said...

awesome site site very helpful. keep posting.

priya said...

how to zoom that item on mouse hover?

Anonymous said...

really superb.

Nandi said...

your codings are really helpful. thanks Suresh

Anonymous said...

very useful thanks

Anonymous said...

sir,m big fan ur website ....every time it help in my projects....thank u sir...

sabanam said...

sir can u give me comment box code which u had used in ur website....

Rameshjogi said...

. Create a Blog Module where user can login and they can post their own blog and other users can review it and they can comment it but they won’t be having an option to delete and edit. Only owner will be having an option to delete and edit.

Suresh Dasari said...

if you want to implement like that means you should check the person who logged in user is the person who posted or not otherwise don't give permission for that....

Anonymous said...

I wanna to send mail through at remote server http// but we could't do this with my and yr codes also please tell me for the remote server to any other like-- abs@xyz....
with only
to-, from, subject-, body, attachment.

Imtiaz said...

how to validate it on button click event, if a title in the database is already exist then user should receive a message on label that change the title or it is already exist.

thank you

zeenat said...

i want to learn about multiview

hemanth said...

nice 1

vijay kumar said...

Very Usefull..


its very useful ....thanks

Magaiana said...

Greeting fellow Devs. (C# & SQL) I need help, i want to displaying items of a specific order number on a repeater control as soon as i add them.. the order number source is a text-box control..

Magaiana said...

Greeting fellow Devs. (C# & SQL) I need help, i want to displaying items of a specific order number on a repeater control as soon as i add them.. the order number source is a text-box control..

Rathinamoorthy N said...

Awesome brother. All your posts are helping me a lot. Thanks :)

Anonymous said...

Really Superb...thanks

Anonymous said...

i need code with rply comment code

Arif Khan said...
This comment has been removed by the author.
anvesh nani said...

Id is not working when we did not allow the nulls,,,,

Sandeep said...

very good and helpful

Ramesh Rajak said...

its very useful ....thanks

Atul said...

Hello Suresh,

It was vry useful..just keep it up.....

Anonymous said...

hi suresh

Anonymous said...

hi can you please tell or upload anything based on checkbox inside a gridiview which is in masterpage and another page which is content page which has datalist in it.. if we click on the checkbox inside gridview the datas should list in contentpage that is inside datalist using ajax or something... can you please upload it

Atul Singh said...

thanx buddy this is very useful to me

Ram said...

nice one

Roopesh Jain said...

there is an error at BindRepeatorData();
how to solve this

Anonymous said...

Nice example with detail explaination

venkatesh said...

can i implement this example for news update where admin of system update the news and user can view the news with image and more button.after clicking the more button user can view the hole news on new page.
like in your website the Recent Posts are working when user click on more button it displaying post on new page. please provide me code sir.

Naisargee Danech said...

U always help me in my work.. Thans sir.. I always use your site.. and also very helfull to me.. thanks..

Anonymous said...

nice...great job mr.suresh

Anonymous said...


S. Welsh said...

Thank you this is a great help for learning to code.

Anonymous said...

i am facing an error
'System.Data.DataRowView' does not contain a property with the name 'Subject'.
in using the Repeater Control.

Anonymous said...

can you please tell ,how to add dynamic column in repeater?

Gummadi Haritha said...

thanks it is very helpfull for beginners....

Anonymous said...

hi, the comment label does not do a line break ..why??

Anonymous said...

sir which databasse u implement and i am gettiing error in Bindreprter()

pramod said...

get me error
which DB ur are using plzz tell me

Anonymous said...


Anonymous said...

Thank u very much.It is too good.

Anonymous said...

Hello Sir,

This is om.I want to send email through at google mail server.So how to send,plz help me....thanks

Jayraj Modi said...

how can i add in repeater download and update panel link...
please most important in my prroject

Gurprit singh said...

wow.. i was looking for this kind of tutorial...
thnx alot

Jitesh Kumar Jha said...

Awesome brother. All your posts are helping me a lot. Thanks :)

Girish Kulkarni said...

hello sir. ur site is very useful, Thanx for the help.

i have a query regarding Repeater

'm having one button in Repeater and i want to fetch the value of 3Labels inside the same repeater. however i have managed to fetch value for 1 label bu i 'm not able to fetch other two..
please suggest something. thankyou :)

ziyad s.v said...

impressive....thnx alot for your valuable codes

Anonymous said...

I got a lots of knowledge from your sites.
Thanks a lot...........

Anonymous said...

nice one..thanks brother..

Shahabuddin said...

Sir this is really helpful,
sir tell me how to reply on a comment and is shows "1comment" under the Posted comment.

Anonymous said...

very helpful.....awesome explaination....

Anonymous said...

How to show images to the use of Repeater Control in .Net?

Atul Rawat said...
This comment has been removed by the author.
sqlservermasters said...

I can see that you are are genuinely passionate about this! I am trying to build my own website and youve helped me with some great information.

Atne said...

very good i enjoy it

Rajeev Kumar said...

this code is not working after refresh the page at refresh i previous data is show on the page i want to no value at page load.

Lakshmi Narasimha said...

* Hi Brother,

Your site helps very well to learners & developers. But Now a days Stored Procedures are using in projects. So please write the articles with SPs now onwards. It is not at big task like you a eminent people.

Thank you.

Anonymous said...


Anonymous said...

Is it possible to perform data deletion using repeater control?

Anonymous said...

How to display a default image if original image is not available in C#

Anonymous said...

I have for repeater control on one page. and have bind data using different ids all four from different ids how do i apply searching on them??

princenathan said...


Anonymous said...

Always valuable thank you sir.

Anonymous said...


shashank rawat said...

how to print current id which is generated at time of submit button click on label text
please reply soon i really need it

rashed bin hares said...


venkat said...

impressive....thnx alot for your valuable codes

Dhiraj said...

what is

Rahul Reddy said...

but without using datasource Plz implement the dataRepeater items

Anonymous said...

gud job sir

Anonymous said...

I need your help......... how can i ask you

Muhammad Ali said...

Thanks Man For Your Great Action.. (Y)

Harshil Parekh said...


Govind Maske said...

thank u very much

Anonymous said...

How to bind dynamically created datatable to repeater control..

I have done binding but it shows nothing

Mullagura Himabindu said...
This comment has been removed by the author.
Anonymous said...

This Article is very nice,
But I have a doubt,"If I insert an Like Imagebutton, i want to know the count of image button clicked". How can i implement that..!!
Plz help me..

Anonymous said...

what if I want to reply to a particular comment , instead of simply writing at the end...

Anonymous said...

How to bind created datatable to repeater control using radiobutton..

I have done binding but it shows nothing

Kaminepalli Naveen said...

Superb sir thanks

amna naveed said...

very nice code help me alot and now i want to make some changes in it once the user add first post then at the bottom of that post i add comment bt when i do next post then the post is added at the bottom now i want to do is i want to break this repeater for example when i add new post i ll display in new repeater

Rajeshwar Loka said...

Suresh thank you for your reply but here my task is i have a html editor and when i submit text is displaying in gridview row here the question is i gave a hyperlink in the same grid row when i submit text the text should be saved in the form of pdf file and when ever i click on hyperlink i can be able to download the text as pdf file and also i want a reply button or a link in grid row where i can be able to reply for the particular comment pls help me as soon as possible

Bhuva Bhavesh said...

Very useful Example..
Thank You....

mp3musicmazaa said...

Hi brother
This example is useful
but tell me how to use Data pager with Repeater above example code
Please help me

Anonymous said...

very good explanation and quite enough to get the concept through

Selva Kumar said...

how to reply for particular comment

Anonymous said...

Thank you so much and you have done good job

Anonymous said...

nice pagle.....

Onah Venture said...

nice work. Please how can i create a reply to each comment

Narender Godara said...

I have 10 records in my database. How can i show last 5 (6 to 10) records from database in repeater.

Anonymous said...

abcvfdsf 6546546

Anonymous said...

Your code runs into runtime Exception " System.Web.HttpException: You can only have one runat="server" control on a page."

Unknown said...

Very awesome sir !!!
You such a genius...

Anonymous said...

i want repeater output as the row format

Avik Mondal said...

how can make nested comments reply..

Anonymous said...

Thank you! Very helpful.

Unknown said...

please upload reply button cs code

arul said...

Dear sir,
Kindly provide with REPLY button

PostIndia said...

Thank you! Very helpful.

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.