Net-informations.com
SiteMap  | About    

Repeater with HTML Table

The ASP.NET Repeater is a basic container control that allows you to create custom lists from any data available to the page. It render HTML to display the contents of a list or data source to which they are bound.

repeater-table

We can integrate a Repeater control with HTML Table. We should start a HTML table tag in the Header template and end the HTML table tag in the Footer template.

  

<HeaderTemplate>
  <table >
</HeaderTemplate>
<FooterTemplate>
  </tabel>
</FooterTemplate>

The following program also display an image inside the Repeater control. In order o display an image we are retrieving the image path from database values and embeded in the asp Image tag.

  

<asp:Image ID="Image1" height="31" width="127"
Img src='<%# DataBinder.Eval(Container.DataItem, "website_logo")%>' runat="server"/>

The above code retrieve the image path value from the website_logo database field. The following ASP.NET program retrieves the values from an XML file and display in the web page. The XML database file has two fields website_logo and website_name. The website_logo field contain the path of logo image and website_name contain the websites name.

vb.net
  Dim ds As New DataSet

ds.ReadXml("D:\websites.xml")

C#
  DataSet ds = new DataSet();

ds.ReadXml(@"D:\websites.xml");

Copy and paste the following XML content to a notepad and save it as c:\websites.xml , or Download websites.xml from here and save it to c:\websites.xml.

  

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Table>
	<websites>
		<website_logo>http://net-informations.com/logo.png</website_logo>
		<website_name>http://net-informations.com</website_name>
	</websites>
	<websites>
		<website_logo>http://net-informations.com/logo.png</website_logo>
		<website_name>http://vb.net-informations.com</website_name>
	</websites>
	<websites>
		<website_logo>http://net-informations.com/logo.png</website_logo>
		<website_name>http://csharp.net-informations.com</website_name>
	</websites>
	<websites>
		<website_logo>http://net-informations.com/logo.png</website_logo>
		<website_name>http://asp.net-informations.com</website_name>
	</websites>
</Table>

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Repeater id="repeater1" runat="server" >
		<HeaderTemplate>
		<table border="2">
		<tr><td colspan ="2"><b><u>Website Listing</u></b><br /></td></tr>
		</HeaderTemplate>
		<ItemTemplate>
		<tr><td>
		<asp:Image ID="Image1" height="31" width="127"
		Img src='<%# DataBinder.Eval(Container.DataItem, "website_logo")%>' runat="server"/>
		</td><td>
		<%# DataBinder.Eval(Container.DataItem, "website_name")%> <br />
		</td></tr>
		</ItemTemplate>
		<FooterTemplate>
		<tr><td colspan ="2">All Rights Reserved. </td></tr>
		</tabel>
		</FooterTemplate>
		</asp:Repeater>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.