Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> ASP.Net & Web Forms >> Repeater Control in ASP.Net with C#
Repeater Control in ASP.Net with C#
Repeater Control in ASP.Net with C#


by AVADHESH PATEL on 7/24/2012 9:21:14 PM

Views: 3351       Comments: 0

Repeater Control in ASP.Net with C#

Repeater Control:

The Repeater control performs a very common function that most Web developers have encountered in their projects work. Very often you need to display records from a database, and most likely you would use a FOR loop to write the HTML code so that the records can be displayed within a table. Using the Repeater control, this process can very easily be automated.
A Repeater control is a light weight control which can be used for simple reporting purposes. It supports basic event-handling like In it, Load, Unload etc., This also supports some basic formatting of data and can be presented to the user. A Repeater control offers limited level of data editing or selecting capabilities. For such editing and updates ASP .Net offers DataList and DataGrid controls.
A Repeater control can be used to build small and Flexible reports with the templates for the items. It supports the following five templates.

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 its 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.

Demo on Repeater Control

Step1:-

Create a table in SQL DataBase

CREATE TABLE [dbo].[gridview]

(

      [id] [int] IDENTITY(1,1) NOT NULL,

      [name] [varchar](50) NOT NULL,

      [age] [int] NOT NULL,

      [salary] [decimal](18, 0) NOT NULL,

      [country] [varchar](50) NOT NULL,

      [city] [varchar](50) NOT NULL

)    

 

Step2:- Drag and Drop Repeater Control on aspx page

Step3:- Design Repeater Control for display record according data table

<body>

    <form id="form1" runat="server">

    <div>

    <asp:Repeater ID="Repeater1" runat="server" >

 

    <HeaderTemplate>

    <table>

    <tr>

    <td style="background-color:Gray;width:100px;" >Id</td>

    <td style="background-color:Gray;width:100px;" >Name</td>

    <td style="background-color:Gray;width:100px;" >Age</td>

    <td style="background-color:Gray;width:100px;" >Salary</td>

    <td style="background-color:Gray;width:100px;" >Country</td>

    <td style="background-color:Gray;width:100px;" >City</td>

    </tr>

    </table>

    </HeaderTemplate>

 

    <ItemTemplate>

    <table>

    <tr>

    <td style="background-color:#FFFFFF;width:100px;" >

    <asp:Label ID="lblId" runat="server" Text='<%#Bind("id")%>'></asp:Label>

    </td>

    <td style="background-color:#FFFFFF;width:100px;" >

    <asp:Label ID="lblName" runat="server" Text='<%#Bind("name")%>'></asp:Label>

    </td>

    <td style="background-color:#FFFFFF;width:100px;" >

    <asp:Label ID="lblAge" runat="server" Text='<%#Bind("age")%>'></asp:Label>

    <td style="background-color:#FFFFFF;width:100px;" >

    <asp:Label ID="lblSalary" runat="server" Text='<%#Bind("salary")%>'></asp:Label>

    </td>

    <td style="background-color:#FFFFFF;width:100px;" >

    <asp:Label ID="lblCountry" runat="server" Text='<%#Bind("country")%>'></asp:Label>

    <td style="background-color:#FFFFFF;width:100px;" >

    <asp:Label ID="lblCity" runat="server" Text='<%#Bind("city")%>'></asp:Label>

    </tr>

    </table>  

    </ItemTemplate>

 

    </asp:Repeater>

   

    </div>

    </form>

</body>

 

Design View of Repeater Control

Repeater Control in ASP.Net with C#

Step 4:- Bind the Repeater Control to DataTable

using System;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        string conString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;

        SqlConnection con = new SqlConnection(conString);

        SqlDataAdapter adap = new SqlDataAdapter("select * from gridview", con);

        DataTable dt = new DataTable();

        adap.Fill(dt);

        Repeater1.DataSource = dt;

        Repeater1.DataBind();

    }

}

 

Step5:- Run the web page and see output

Repeater Control in ASP.Net with C#

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by AVADHESH PATELRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2499
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.