Repeater Control :
The Repeater control is used to display a repeated
list of items that are bound to the control. The Repeater control may be bound
to a database table, an XML file, or another list of items. Repeater control is
an iterative control in the sense it loops each record in the DataSource and
renders the specified template (ItemTemplate) for each record in the DataSource
collection.
To use Repeater Control drag it
form ToolBox left pane into your .aspx file or write the following ASP.Net
Repeater Control in your .aspx file.
<asp:Repeater
ID="Repeater1" runat="server"></asp:Repeater>
Example:
Here we are making a List to add dynamically main category item and their sub
category item with help of Repeater Control.
<body>
<form id="form1" runat="server">
<div style="height: 462px; width: 906px;">
<%-- // table to
take maincategory item --%>
<table id
="main_Category"
style="position:absolute; top: 51px; left: 46px; height: 50px; width: 540px;" border="1px">
<tr style="background-color:DarkOrange">
<td class="style1">
<asp:Label ID="Label1" runat="server" ForeColor="White"
Text="Enter Main
Category Name :: " BackColor="DarkOrange"></asp:Label>
</td>
<td class="style1">
<asp:TextBox ID="TextBox1" runat="server" Width="213px " AutoComplete ="off"
></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Add" onclick="Button1_Click" />
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<%-- //Asp.Net Repeater Control to add Main
Category Item--%>
<asp:Repeater ID="MainRepeater" runat="server"
onitemcommand="MainRepeater_ItemCommand" onitemdatabound="MainRepeater_ItemDataBound"
>
<HeaderTemplate><ul>
<asp:Label ID="Label4"
runat="server" Text="Articles" BackColor="DarkOrange" ForeColor="White" Width="50%" BorderWidth="1px" ></asp:Label>
<br></br>
</HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<table border="1px" width="50%" style=" border-bottom-width:1px; border-bottom-color:Purple">
<tr style="background-color:DarkOrange">
<td style="border-bottom-width:1px">
<%--//Bind main Category table item with main Repeater control
--%>
<asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"CategoryName")
%>'
Width="145px" BackColor="DarkOrange" ForeColor="White">></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Add"
/>
</td>
</tr>
</table>
<%-- //Child Repeater
Control in ASP.Net to repeat subcategory item list --%>
<asp:Repeater ID="ChildRepeater" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<li>
<%-- // Bind subcategory
table item with child repeater control--%>
<asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SubCategoryName")
%>'>></asp:Label></li>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>