Net-informations.com
SiteMap  | About    

ASP.NET Repeater Templates

The Repeater control that render HTML to display the contents of a list or data source to which they are bound. It has no built-in layout or styles, so you must explicitly declare all layout, formatting, and style tags within the controls templates.

repeater-template

At a minimum, every Repeater control must define an ItemTemplate. Other optional templates can be used to customize the appearance of the list. They are ItemTemplate, AlternatingItemTemplate , SeparatorTemplate , HeaderTemplate and FooterTemplate.

ItemTemplate is required by the Repeater control and it produces one row of output for each data row. AlternatingItemTemplate is same as ItemTemplate and it renders for every other data row. HeaderTemplate and FooterTemplate render HTML immediately before and after all the data rows have been rendered and finally SeparatorTemplate render items between each data row like the HTML tags br, p, or HR.

The following ASP.NET program shows how to use Templates in Repeater Control.

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" DataSourceID="SqlDataSource1">
		<HeaderTemplate>
		<b><u>HEADER TEXT HERE</u></b><hr>
		</HeaderTemplate>
		<ItemTemplate>
		<%# DataBinder.Eval(Container.DataItem, "stor_id")%> &nbsp;&nbsp;
		<%# DataBinder.Eval(Container.DataItem, "stor_name")%> <br />
		</ItemTemplate>
		<SeparatorTemplate>
		<hr>
		</SeparatorTemplate>
		<FooterTemplate>
		<hr><b><u>FOOTER TEXT HERE</u></b>
		</FooterTemplate>
		</asp:Repeater>
		<asp:SqlDataSource ID="SqlDataSource1" runat="server"
		ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
		SelectCommand="select [stor_id],[stor_name] from stores" />
	</div>
	</form>
</body>
</html>







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