.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Implementation of Repeater Control in ASP.NET Applications

Posted By:Ashutosh Jha       Posted Date: July 26, 2014    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

In this article I will explain the repeater control, uses of repeater control and how one can implement repeater control in asp.net.

In this article I am going to explain the repeater control, uses of repeater control and how one can implement repeater control in asp.net applications. Repeater Control is a control which is used to display the repeated list of items. Like if we need to display the prescription of a doctor which he/she gave to the client. Here we can use of it.

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


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.

Create a table named details having rows-

Now create a page named (suppose) repeater.aspx.

<asp:Repeater ID="RepDetails" runat="server">
<td colspan="2">
<asp:Label ID="lblname" runat="server" Text='<%#Eval("name") %>'/>
<asp:Label ID="lbladdress" runat="server" Text='<%#Eval("address") %>'/>
<asp:Label ID="lblcompany" runat="server" Text='<%#Eval("company") %>'/>

Now bind this repeater control with the database table that you have created just above. In repeater.aspx.cs page have the following-
in the namespace add the below-
using System.Data;
using System.Data.SqlClient;
using system.configuration;

at page load method write the below-


now bind the data. If you want the data to be displayed at the page load it self write a method in page load event-

protected void binddata();
SqlCommand cmd = new SqlCommand("select * from details Order By id desc", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
RepDetails.DataSource = ds;

Now execute your web page and check the output !!

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend