Repeater Example in ASP.NET using C#

Repeater Example in ASP.NET using C#


Posted in : ASP.Net Posted on : December 8, 2010 at 4:09 PM Comments : [ 0 ]

In this article we will introduce with Repeater control in ASP.NET using C#.

Repeater Example in ASP.NET using C#

Repeater control in ASP.NET is used to display repeated list of items that are bound to the control. Repeater control is a data bind control. You can use the database table, XML file or any other data source for bind the data.
Repeater control has five template to format it.

1. HeaderTemplate
2. FooterTemplate
3. ItemTemplate
4. AlternatingItemTemplate
5. SeperatorTemplate

Repeater.aspx (Design Page):

Repeater.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" 
AutoEventWireup="true" CodeFile="Repeater.aspx.cs" Inherits="Repeater" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.tblcolor
{background-color:Silver;}
.rowcolor
{background-color:Green;font-weight:bold;}
.footercolor
{background-color:Black;color:White;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<h2 style="color:Green">Repeater in ASP.NET 4, C#</h2>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table class="tblcolor">
<tr class="rowcolor">
<b><td>ProductID</td>
<td>Product Name</td>
<td>Price</td></b>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="tblrowcolor">
<td><%#DataBinder.Eval(Container, "DataItem.ProductID")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.ProductName")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.Price")%></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td><hr /></td>
<td><hr /></td>
<td><hr /></td>
</tr>
</SeparatorTemplate>
<AlternatingItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container, "DataItem.ProductID")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.ProductName")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.Price")%></td>
</tr>
</AlternatingItemTemplate>
<SeparatorTemplate>
<tr>
<td><hr /></td>
<td><hr /></td>
<td><hr /></td>
</tr></SeparatorTemplate>FooterTemplate>
<tr class="footercolor">
<td>Product Record Displayed</td>
<td></td>
<td></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
&nbsp;&nbsp;&nbsp;
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" 
DeleteCommand="DELETE FROM [Product] WHERE [ProductID] = @ProductID" 
InsertCommand="INSERT INTO [Product] ([ProductID], [ProductName], 
[Price]) VALUES (@ProductID, @ProductName, @Price)" 
SelectCommand="SELECT * FROM [Product]" 
UpdateCommand="UPDATE [Product] SET [ProductName] = @ProductName, 
[Price] = @Price WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="Price" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</asp:Content>

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics