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


Top 5 Contributors of the Month
david stephan

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 
AlternatingitemTemplate
HeaderTemplate 
FooterTemplate
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.

Create a table named details having rows-
Id
name
address
company

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

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

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-

if(!IsPostBack)
{
binddata();
}

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();
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from details Order By id desc", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
RepDetails.DataSource = ds;
RepDetails.DataBind();
conn.Close();
}

Now execute your web page and check the output !!

 Subscribe to Articles

     

Further Readings:

Responses

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